curl cookie和post用法

<?php
/*
#利用cookie和post用法
*/

$ch = curl_init();
curl_setopt($ch, CURLOPT_COOKIEJAR, "E:/sq/curl/cookie.txt");
curl_setopt($ch, CURLOPT_URL,"http://www.nbchem.com/user/login.php");
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, "user=yourname&password=pwd&act=1");

ob_start();      // prevent any output
curl_exec ($ch); // execute the curl command
ob_end_clean();  // stop preventing output

curl_close ($ch);
unset($ch);

$ch = curl_init();
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch, CURLOPT_COOKIEFILE, "E:/sq/curl/cookie.txt");
curl_setopt($ch, CURLOPT_URL,"http://www.nbchem.com/vip/");

$buf2 = curl_exec ($ch);

curl_close ($ch);
echo $buf2;
//echo "<PRE>".htmlentities($buf2)."</PRE>";
?>

 

你可能感兴趣的:(PHP)