使用cURL从其他网站读取cookie

时间:2012-06-09 05:27:52

标签: php cookies

假设我有一个名为somewebsite.com的网站并且它有cookie,我如何使用cURL在我的域中获取这些cookie,我确实尝试使用此方法执行此操作(来自stackoverflow,但似乎不起作用)

/* STEP 1. let’s create a cookie file */
$ckfile = tempnam ("/tmp", "CURLCOOKIE");
/* STEP 2. visit the homepage to set the cookie properly */
$ch = curl_init ("http://somedomain.com/");
curl_setopt ($ch, CURLOPT_COOKIEJAR, $ckfile); 
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, true);
$output = curl_exec ($ch);

/* STEP 3. visit cookiepage.php */
$ch = curl_init ("http://somedomain.com/cookiepage.php");
curl_setopt ($ch, CURLOPT_COOKIEFILE, $ckfile); 
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, true);
$output = curl_exec ($ch);

0 个答案:

没有答案