dsjz1119 2013-11-28 08:43
浏览 678
已采纳

curl_setopt使用CURLOPT_COOKIESESSION,CURLOPT_COOKIEJAR,CURLOPT_COOKIEFILE返回false

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

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...

  • 写回答

1条回答 默认 最新

  • dsfsfsfsfs55656 2013-11-28 09:29
    关注

    I don't know why, but Curl was compiled without cookies support. Just reinstalled it with --enable-cookies - that's it.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 对于相关问题的求解与代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料