php 5.6 - PHP setcookie not working despite headers looking right -
i handling post request, setting cookie , redirecting user so:
// (handle post request) // fine set cookie $ciphertext = crypto::encrypt($_post['soulmates_member_id'], key::loadfromasciisafestring($this->encryption_key)); $expires = 60 * 60 * 24 * 30; setcookie('soulmates_member_id', $ciphertext, $expires, '/', $_server['http_host']); // redirect header("location: ".$_post['soulmates_redirect']);
the following response returned:
http/1.1 302 found date: tue, 28 jun 2016 10:53:21 gmt server: apache/2.4.17 (win32) openssl/1.0.2d php/5.6.21 x-powered-by: php/5.6.21 expires: wed, 11 jan 1984 05:00:00 gmt cache-control: no-cache, must-revalidate, max-age=0 pragma: no-cache access-control-allow-origin: http://local.wordpress.com access-control-allow-credentials: true x-robots-tag: noindex x-content-type-options: nosniff x-frame-options: sameorigin set-cookie: soulmates_member_id=def5020032ce3903334d3564b22303993dc3bd5923256632200d94785aa9cd09a44091a124848bd4476768eb5027082b01ec4036c4fa366ba41613157d548285d8cbee1b1115b0fc3ec454127e62732db13fb72b4ff385eceeae1b7af7c1; expires=sat, 31-jan-1970 00:00:00 gmt; max-age=-1464519202; path=/; domain=local.wordpress.com location: http://local.wordpress.com/another-page/ content-length: 0 keep-alive: timeout=5, max=100 connection: keep-alive content-type: text/html; charset=utf-8
but cookie doesn't set. i've tried in chrome , firefox , cookie doesn't set reason.
i solved it! it's because expires time needs relative expiry date , time in future so:
$expires = time() + 60 * 60 * 24 * 30;
Comments
Post a Comment