$ch = curl_init(); $c_url = 'http://www.baidu.com'; $c_url_data = "product_&type=".$type.""; curl_setopt($ch, CURLOPT_URL,$c_url); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_POSTFIELDS, $c_url_data); echo $result = curl_exec($ch); curl_close ($ch); unset($ch);
// create a new curl resource $ch = curl_init(); // set URL and other appropriate options curl_setopt($ch, CURLOPT_URL, “http://www.google.nl/”); // grab URL and pass it to the browser curl_exec($ch); // close curl resource, and free up system resources curl_close($ch); ?>
// create a new curl resource
$ch = curl_init();
// set URL and other appropriate options
curl_setopt($ch, CURLOPT_URL, “http://www.google.nl/”);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
// grab URL, and return output
$output = curl_exec($ch);
// close curl resource, and free up system resources
curl_close($ch);
// Replace ‘Google' with ‘PHPit'
$output = str_replace('Google', ‘PHPit', $output);
// Print output
echo $output;
?>
// create a new curl resource $ch = curl_init(); // set URL and other appropriate options curl_setopt($ch, CURLOPT_URL, “http://www.google.com/”); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); // grab URL, and print curl_exec($ch); ?>
// create a new curl resource
$ch = curl_init();
// set URL and other appropriate options
curl_setopt($ch, CURLOPT_URL,”http://projects/phpit/content/using%20curl%20php/demos/handle_form.php”);
// Do a POST
$data = array('name' => ‘Dennis', 'surname' => ‘Pallett');
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
// grab URL, and print
curl_exec($ch);
?>
And the handle_form.php file:
echo ‘Form variables I received:';
echo ‘';
print_r ($_POST);
echo ‘';
?>
// create a new curl resource $ch = curl_init(); // set URL and other appropriate options curl_setopt($ch, CURLOPT_URL, “http://sc.365jz.com/”); curl_setopt($ch, CURLOPT_USERAGENT, ‘My custom web spider/0.1′); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); // grab URL, and print curl_exec($ch); ?>
// create a new curl resource $ch = curl_init(); // set URL and other appropriate options curl_setopt($ch, CURLOPT_URL, “http://www.google.com”); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_FILETIME, true); // grab URL $output = curl_exec($ch); // Print info echo ‘'; print_r (curl_getinfo($ch)); echo ‘'; ?>
// create a new curl resource
$ch = curl_init();
// set URL and other appropriate options
curl_setopt($ch, CURLOPT_URL, “http://www.google.com/does/not/exist”);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
// grab URL
$output = curl_exec($ch);
// Get response code
$response_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
// Not found?
if ($response_code == ‘404′) {
echo ‘Page doesn\'t exist';
} else {
echo $output;
}
?>
如对本文有疑问,请提交到交流论坛,广大热心网友会为你解答!! 点击进入论坛