Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/284.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 使用cURL接受cookies?_Php_Cookies_Curl_File Get Contents - Fatal编程技术网

Php 使用cURL接受cookies?

Php 使用cURL接受cookies?,php,cookies,curl,file-get-contents,Php,Cookies,Curl,File Get Contents,我一直在尝试使用cURL获取网页内容,但在让cURL接受cookies时遇到了困难。 例如,在Target.com上,当我卷曲它时,它仍然说我必须启用cookies 这是我的密码: $url = "http://www.target.com/p/Acer-Gateway-15-6-Laptop-PC-NV57H77u-with-320GB-Hard-Drive-4GB-Memory-Black/-/A-13996190#?lnk=sc_qi_detailbutton"; $ch = curl_i

我一直在尝试使用cURL获取网页内容,但在让cURL接受cookies时遇到了困难。 例如,在Target.com上,当我卷曲它时,它仍然说我必须启用cookies

这是我的密码:

$url = "http://www.target.com/p/Acer-Gateway-15-6-Laptop-PC-NV57H77u-with-320GB-Hard-Drive-4GB-Memory-Black/-/A-13996190#?lnk=sc_qi_detailbutton";
$ch = curl_init();    // initialize curl handle
curl_setopt($ch, CURLOPT_URL,$url); // set url to post to
curl_setopt($ch, CURLOPT_FAILONERROR, 1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);// allow redirects
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1); // return into a variable
curl_setopt($ch, CURLOPT_TIMEOUT, 10); // times out after 4s
curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.7; rv:11.0) Gecko/20100101 Firefox/11.0"); 
$cookie_file = "cookie1.txt";
curl_setopt($ch, CURLOPT_COOKIESESSION, true);
curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie_file);
curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie_file);
$result = curl_exec($ch); // run the whole process
curl_close($ch); 
echo $result;
我还缺什么?
顺便说一下,cookie1.txt文件是077权限。

077是一个格式错误的权限设置,这意味着所有者(可能是apache)没有访问权限。尝试将其设置为644(所有者已读/写),因为它只是一个文件

077是无效权限,这意味着所有者(可能是apache)没有访问权限。尝试将其设置为644,因为它只是一个文件。@MikePurcell为什么要将其作为注释发布?将其作为答案发布。@Truth:我不确定它是否是一种类型。嗨,你找到你的问题了吗?