curl_setopt使用CURLOPT_COOKIESESSION,CURLOPT_COOKIEJAR,CURLOPT_COOKIEFILE返回false [英] curl_setopt returning false with CURLOPT_COOKIESESSION, CURLOPT_COOKIEJAR, CURLOPT_COOKIEFILE
问题描述
FreeBSD下的PHP 5.4.19版本
PHP version 5.4.19 under FreeBSD
$ch = curl_init();
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); //returns true
curl_setopt($ch, CURLOPT_HEADER, true); //returns true
curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.2) Gecko/20100115 Firefox/3.6'); //returns true
curl_setopt($ch, CURLOPT_TIMEOUT, 100); //returns true
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); //returns true
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false); //returns true
var_dump(curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false) ); //true
var_dump( curl_setopt($ch, CURLOPT_COOKIESESSION, 1) ); //returns false ????
var_dump( curl_setopt($ch, CURLOPT_COOKIEJAR, '/tmp/cookie') ); //returns false ????
var_dump( curl_setopt($ch, CURLOPT_COOKIEFILE, '/tmp/cookie') ); //returns false ????
var_dump( curl_setopt($ch, CURLINFO_HEADER_OUT, true) ); //true
我还注意到,即使没有CURLOPT_COOKIESESSION,CURLOPT_COOKIEJAR,CURLOPT_COOKIEFILE,Curl也不会在单个处理程序中的请求之间传递任何cookie.这是一些标题日志,以了解我在说什么:
I've also noticed, that even without CURLOPT_COOKIESESSION, CURLOPT_COOKIEJAR, CURLOPT_COOKIEFILE - Curl is not passing any cookie between requests in single handler. Here is some headers log to understand what I'm talking about:
GET /login.php HTTP/1.1
User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.2) Gecko/20100115 Firefox/3.6
Host: domain.com
Accept: */*
HTTP/1.1 302 Moved Temporarily
Server: nginx
Date: Thu, 28 Nov 2013 08:25:57 GMT
Content-Type: text/html
Transfer-Encoding: chunked
Connection: keep-alive
Set-Cookie: PHPSESSID=bev3mvr9s27jgq5vvm43s56pb2; path=/
Expires: Thu, 19 Nov 1981 08:52:00 GMT
Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0
Pragma: no-cache
Location: go.php?PHPSESSID=bev3mvr9s27jgq5vvm43s56pb2
HTTP/1.1 302 Moved Temporarily
Server: nginx
Date: Thu, 28 Nov 2013 08:25:57 GMT
Content-Type: text/html; charset=utf-8
Transfer-Encoding: chunked
Connection: keep-alive
Set-Cookie: PHPSESSID=m8uddnk1q55s634fu7frnt2lo3; path=/
#session cookie has changed; Curl didn't use PHPSESSID cookie from login.php
Expires: Thu, 19 Nov 1981 08:52:00 GMT
Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0
Pragma: no-cache
Location: login.php
更新:我已经在另一台主机上尝试了相同的代码-一切正常.嗯...
UPDATE: I've tried the same code on another host - everything is ok. Hm...
推荐答案
我不知道为什么,但是Curl是在没有Cookie支持的情况下编译的.只需使用-enable-cookies
重新安装-就是这样.
I don't know why, but Curl was compiled without cookies support. Just reinstalled it with --enable-cookies
- that's it.
这篇关于curl_setopt使用CURLOPT_COOKIESESSION,CURLOPT_COOKIEJAR,CURLOPT_COOKIEFILE返回false的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!