Wednesday, October 21, 2009

curl とCookie

$useragent = 'User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)';
$cookie_save_file = 'cookie_data';

$url = 'http://example.com/test.php';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_TIMEOUT, 2);
curl_setopt ($ch,CURLOPT_POST,1);
$post_word = "input=了承";
curl_setopt($ch,CURLOPT_POSTFIELDS,$post_word);
curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie_save_file);// 読み込まれるファイル
curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie_save_file);// 内容が保存される。
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_USERAGENT, $useragent);
$content = curl_exec($ch);
curl_close($ch);

echo $content;

No comments: