我正在使用 cURL 检索另一个页面,除非我有特定的 cookie,否则我看不到页面内容。 cookie 名称是 seepage
,它的值必须设置为 1 才能让我看到页面内容。
我想使用 cURL 加载此页面,这是我目前拥有的脚本:
<?php
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'http://www.pixhost.org/images/531/1245992_untitled-2.jpg');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_COOKIE, 'tmpfile.tmp');
curl_setopt($ch, CURLOPT_COOKIEJAR, 'tmpfile.tmp');
curl_setopt($ch, CURLOPT_COOKIEFILE, 'tmpfile.tmp');
curl_setopt($ch, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']);
$result = curl_exec($ch);
print_r($result);
?>
但是,$result 是一个空变量,我可以用 if(empty($result))
确认。我如何设置 cURL 以使用名为 seepage
且 cookie 值为 1
的 cookie?
谢谢。
最佳答案
cookie 的值为'seepage=1':
curl_setopt($ch, CURLOPT_COOKIE, 'seepage=1');
并且您需要删除 CURLOPT_COOKIEFILE 的现有行
关于php - 设置一个 cookie 供 cURL 使用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1995850/