简体   繁体   中英

cURL cookie negative cookie expire

I have problems with cookies with cURL.

After problems I turned on verbose function and figured out cURL sets them negative expire date even if server sends positive date.

Example:

* Added cookie _c_sess=""test"" for domain test.com, path /, expire -1630024962
< Set-Cookie: _c_sess="test"; Domain=test.com; HttpOnly; expires=Mon, 26-Mar-2012 14:52:47 GMT; Max-Age=1332773567; Path=/

As you can see both expires and max-age are positive, but cURL sets expire to negative value.

Somebody has idea?

EDIT:

Here is php code I use.

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "http://site.com/");
curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows NT 6.1; rv:11.0) Gecko/20100101 Firefox/11.0');
curl_setopt($ch, CURLOPT_COOKIEJAR, $cookiepath);
curl_setopt($ch, CURLOPT_COOKIEFILE, $cookiepath);
curl_setopt($ch, CURLOPT_HEADER  ,1);
curl_setopt($ch, CURLOPT_VERBOSE  ,1);
curl_setopt($ch, CURLOPT_STDERR  ,$f);
curl_setopt($ch, CURLOPT_RETURNTRANSFER  ,1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION  ,1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
$data = curl_exec($ch);

Data from cookie jar:

#HttpOnly_.test.com TRUE    /   FALSE   -1630016318 _test_sess  "test"

可能是与Curl无法正确识别cookie中的过期值相同的问题-“由于32位带符号整数值的限制,您在计算机上遇到了问题。”

Your code works fine for me. Your example site, http://www.site.com/ does not even attempt to set any cookies. When I ran it against sites that set cookies (ie FaceBook), I got positive expiration times.

The error is probably an issue on the server that is trying to set cookies that is setting an incorrect value.

Any negative number will expire the cookie immediately ( cite ).

My best guess, the site is trying to expire your cookie.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM