php – Curl无法正确识别cookie中的expires值
我正在尝试使用curl在pinterest.com上登录.我得到了以下请求 – 响应流程:
> GET-请求登录表单并抓取隐藏字段(csrftoken) 使用Curl,我可以看到发送和接收的以下标题: GET /login/?next=%2F HTTP/1.1 User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:10.0.2) Gecko/20100101 Firefox/10.0.2 Host: pinterest.com Referer: Accept: text/html,application/xhtml+xml,application/xml,*/* Accept-Language: de-de,en-us Connection: keep-alive HTTP/1.1 200 OK Content-Type: text/html; charset=utf-8 Date: Tue,10 Apr 2012 15:03:24 GMT ETag: "45d6a85f0ede46f13f4fc751842ce5b7" Server: nginx/0.8.54 Set-Cookie: csrftoken=dec6cb66064f318790c6d51e3f3a9612; Max-Age=31449600; Path=/ Set-Cookie: _pinterest_sess="eJyryMwNcTXOdtI3zXcKNq0qznIxyXVxK/KqSsy3tY8vycxNtfUN8a3yc3E09nXxLPdztLVVK04tLs5MsfXNAopVpVf6VnlW+Qba2gIAuqgZIg=="; Domain=pinterest.com; HttpOnly; expires=Tue,17-Apr-2012 15:03:24 GMT; Max-Age=1334675004; Path=/ Vary: Cookie,Accept-Encoding Content-Length: 4496 Connection: keep-alive 因此,在步骤1之后,设置两个cookie csrftoken和_pinterest_sess.但是看看cookiejar文件(我使用CURLOPT_COOKIEFILE和CURLOPT_COOKIEJAR让curl处理cookie处理)显示如下: # Netscape HTTP Cookie File # http://curl.haxx.se/rfc/cookie_spec.html # This file was generated by libcurl! Edit at your own risk. pinterest.com FALSE / FALSE 1365519805 csrftoken dec6cb66064f318790c6d51e3f3a9612 #HttpOnly_.pinterest.com TRUE / FALSE -1626222087 _pinterest_sess "eJyryMwNcTXOdtI3zXcKNq0qznIxyXVxK/KqSsy3tY8vycxNtfUN8a3yc3E09nXxLPdztLVVK04tLs5MsfXNAopVpVf6VnlW+Qba2gIAuqgZIg==" 首先要注意的是_pinterest_sess cookie行之前的#HttpOnly_.我只是假设卷曲处理得很好.但进一步观察,可以看到负值被设定为到期日:-1626222087 我不知道它来自哪里,因为cookie设置为“expires = Tue,2012年4月17日15:03:24 GMT”(未来约7天,从今天算起). 在下一个请求中,curl不会设置_pinterest_sess cookie: POST /login/?next=%2F HTTP/1.1 User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:10.0.2) Gecko/20100101 Firefox/10.0.2 Host: pinterest.com Referer: https://pinterest.com/login/?next=%2F Cookie: csrftoken=dec6cb66064f318790c6d51e3f3a9612 Accept: text/html,en-us Connection: keep-alive Content-Length: 123 Content-Type: application/x-www-form-urlencoded HTTP/1.1 302 FOUND Content-Type: text/html; charset=utf-8 Date: Tue,10 Apr 2012 15:05:26 GMT ETag: "d41d8cd98f00b204e9800998ecf8427e" Location: http://pinterest.com/ Server: nginx/0.8.54 Set-Cookie: _pinterest_sess="eJzLcssPCy4NTclIjvAOrjQzyywoCChISgvLDi+2tY9PrSjILEottvUN8a3yc4k09gtxrfRLt7VVK04tLs5MAYonV/qGeFb4ZkWW+4LES4tTi+KBEv4u6UZ+WYEmvlm+QOxZ6R/iWOEbEmgLAKNfJps="; Domain=pinterest.com; HttpOnly; expires=Tue,17-Apr-2012 15:05:26 GMT; Max-Age=1334675126; Path=/ Vary: Cookie Content-Length: 0 Connection: keep-alive 在响应中,设置了另一个_pinterest_sess cookie,因为curl没有发送最后一个. 目前,我不知道我做错了什么,或者curl是否无法正确解析cookie中的expires值. 任何帮助将不胜感激 :) //编辑 >太阳报,1994年11月6日08:49:37 GMT 它们都不匹配上述过期日期“Tue,17-Apr-2012 15:03:24 GMT”,因为所有带连字符的例子仅使用2位数年份. 解决方法
由于32位有符号整数值的限制,您在计算机上遇到问题.
服务器将来设置一个Max-Age为1334675004秒的cookie. Max-Age=1334675004 你在这里发表了你的问题@ 2012-04-10 15:13:24Z.这是UNIX时间戳1334070804.如果您向它添加1334675004并且在进行整数往返时考虑32位整数限制2147483647,您将得到:-1626221485: 1334070804 + 1334675004 ------------ -1626221485 如数字所示,看起来服务器确实误解了Max-Age属性,如果你减去彼此的每个值,就会有一个7天的大约三角形(604200 = ~6.99天,差异是因为cookie比你在这里发布你的问题早了.)但Max-Age是秒的增量,而不是绝对的UNIX时间戳. 尝试使用PHP版本提高PHP_INT_MAX,或者针对64位编译,这应该可以防止负数.但是,服务器仍然会破坏max-age计算.您可能需要联系pinterest.com并报告问题. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |