Friday, September 24, 2010

PHP - How to get a result from cURL method

This is the code of the relevant page :
---------------------------------------------------------------------------
if(isset($_GET["requestcode"]))
{
echo $_GET["requestcode"]." Request Successfully Received";
}
---------------------------------------------------------------------------
This is the page that cURL executing
---------------------------------------------------------------------------
$httpString = "http://www.mysite.com/Request.php?requestcode=1254";
$url = $httpString;
$ch = curl_init(); // initialize curl handle
curl_setopt($ch, CURLOPT_URL,$url); // set url to post to
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1); // return into a variable
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_TIMEOUT, 4);
curl_setopt($ch,CURLOPT_PORT,80);

$result = curl_exec($ch);

echo $result;
---------------------------------------------------------------------------
Output will be
---------------------------------------------------------------------------
1254 Request Successfully Received";
---------------------------------------------------------------------------

No comments:

Post a Comment