I am doing a curl in PHP to post data on site and echo the result but it doesn’t post data
here is my code:
<?php
$imei = "imei=XXXXXXXXX";
//set POST variables
$url = 'http://XXX.com/XXX.php';
//open connection
$ch = curl_init();
//set the url, number of POST vars, POST data
curl_setopt($ch,CURLOPT_URL, $url);
curl_setopt ($ch, CURLOPT_POST, true);
curl_setopt($ch,CURLOPT_POSTFIELDS, $imei);
curl_setopt ($ch, CURLOPT_REFERER, 'http://www.XXX.com');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_STDERR, fopen('php://output', 'w+'));
curl_setopt($ch, CURLOPT_VERBOSE, 1);
//execute post
$result = curl_exec($ch);
//close connection
curl_close($ch);
echo $result;
echo $imei;
?>
when i echo $imei, it shows up the full string but data isn’t passed :S
Please help, what’s wrong with code??
Thanks in advance
Update: In the orgignal html of the website it’s name=”imei” not id=”imei”
You haven’t set the option
CURLOPT_RETURNTRANSFER. cURL does not return the response if you don’t set this option totrue.I also suggest changing your POST data to an array instead of a string. The cURL option accepts an array and it automatically builds and encodes the string from that. if you build it yourself, you have to encode it as well.
Edit: based on your debug data, I think your resource requires a GET request not post.
You should also set a user-agent, because the site may reject requests without one:
From the Manual: