PHP and CURL
11
Example of how to use CURL with PHP.
// Call page
$cURL = curl_init();
curl_setopt($cURL, CURLOPT_URL,"http://www.myurl.com");
curl_setopt($cURL, CURLOPT_POST, 1);
curl_setopt($cURL, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($cURL, CURLOPT_POSTFIELDS, "foo=1&bar=2");
$strPage = curl_exec($cURL);
curl_close($cURL);
// Output page
die($strPage);






my personal blog:
www.sanbaldo.com
http://php.net/curl
However using die() to output the contents is generally not a good practice. Usually one would echo the output.
Here is a better example:
<?php
// Initialize CURL resource
$cURL = curl_init();
// set URL and other appropriate options
curl_setopt($cURL, CURLOPT_URL,"http://www.myurl.com");
//tells CURL we are going to use POST to send the parameters
curl_setopt($cURL, CURLOPT_POST, true);
// tells CURL not to pass the output directly to the browser
curl_setopt($cURL, CURLOPT_RETURNTRANSFER, true);
// set parameters
curl_setopt($cURL, CURLOPT_POSTFIELDS, "foo=1&bar=2");
// grab URL, return output
$ouput = curl_exec($cURL);
// close CURL resource
curl_close($cURL);
//print the output
echo $output;
?>