简体   繁体   中英

PHP setcookie doesn't work on IE8

the following code doesn't work on IE8. i tried print_r ($_COOKIE) but it returned array(); please help me.

  1 <?php
  2 $currentTime = time();
  3 
  4 $cookieName   = "go.hyde";
  5 $cookiePath   = "/";
  6 $cookieDomain = $_SERVER['SERVER_NAME'];
  7 $cookieValue  = strval($currentTime);       // value is issue time (Unix Time)
  8 $cookieExpire = strval($currentTime + 600); // expire is 10 minutes after issuing cookie
  9 
 10 setcookie($cookieName,
 11     $cookieValue,
 12     $cookieExpire,
 13     $cookiePath,
 14     $cookieDomain);
 15 

try without cookie path and cookie domain

setcookie($cookieName,$cookieValue,$cookieExpire);

check if cookies are enabled in IE

============== EDIT ================

I think I got it, try this:

<?
$currentTime = time();
$cookieName   = "gohyde";
$cookieValue  = strval($currentTime);       // value is issue time (Unix Time)
$cookieExpire = strval($currentTime + 600); // expire is 10 minutes after issuing cookie 
setcookie($cookieName,
$cookieValue,
$cookieExpire);
echo $_COOKIE[$cookieName];
?>

without cookie path and cookie domain. and no "." dot in the cookie name.

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