本帖最后由 OKMAN2009 于 2012-05-08 10:16:44 编辑

解决方案 »

  1.   

    问题可能在于domain值你是不是用本地localhost ?  如此,随意绑个域名再测
      

  2.   

    检查是否浏览器禁用了cookie  
      

  3.   

    是在本地虚拟了一个域名(如:a.cn),在这个域名下IE没用,FF有效。但是同样的代码传到服务器上IE和FF都可以用。
      

  4.   

    setcookie("TestCookie", $value, time()+3600, "/~rasmus/", "example.com", 1);是见是一个time()+3600
    不知,这段说明是啥意思,看看是不是这个原因“
    expire 
    The time the cookie expires. This is a Unix timestamp so is in number of seconds since the epoch. In other words, you'll most likely set this with the time() function plus the number of seconds before you want it to expire. Or you might use mktime(). time()+60*60*24*30 will set the cookie to expire in 30 days. If set to 0, or omitted, the cookie will expire at the end of the session (when the browser closes). 
    Note: You may notice the expire parameter takes on a Unix timestamp, as opposed to the date format Wdy, DD-Mon-YYYY HH:MM:SS GMT, this is because PHP does this conversion internally. 
      

  5.   

    setcookie(name,value,expire,path,domain,secure)
    参数 描述
    name 必需。规定 cookie 的名称。
    value 必需。规定 cookie 的值。
    expire 可选。规定 cookie 的有效期。
    path 可选。规定 cookie 的服务器路径。
    domain 可选。规定 cookie 的域名。
    secure 可选。规定是否通过安全的 HTTPS 连接来传输 cookie。
      

  6.   

    我想还是domain的问题,不指定域的话就不存在这样的问题。
      

  7.   

    本帖最后由 xuzuning 于 2012-05-09 08:46:53 编辑
      

  8.   

    我在本机虚拟1.cn这样一个域名(访问Apache虚拟主机,可以正常访问)
    现设置cookie如下:
    setcookie('php_dbgs6_abc', 'value', time() + 24 * 3600, '/', '1.cn');
    结果无效(IE下不行,FF下是可以的)。setcookie('php_dbgs6_abc', 'value', time() + 24 * 3600, '/');
    这样有效(IE与FF都可以)。
      

  9.   

    domain 该 cookie 有效的域名。  要使 cookie 能在如 example.com 域名下的所有子域都有效的话,该参数应该设为 '.example.com'。虽然 . 并不必须的,但加上它会兼容更多的浏览器。如果该参数设为 www.example.com 的话,就只在 www 子域内有效。细节见 Cookie 规范中的 tail matching。  
      

  10.   

    我做的测试是这样的,建两个文件分别如下:
    s1.php<?php
    //$expire = gmdate('D, d-M-Y H:i:s \\G\\M\\T', time() + 24 * 3600);
    //$domain = '; domain=' . $_SERVER['HTTP_HOST'];
    //header('Set-Cookie: php_dbgs6_abc=121111ie; expires=' . $expire . '; path=/' . $domain . '; HttpOnly', false); // 无效//setcookie('php_dbgs6_abc', '121111ie', time() + 24 * 3600, '/', '.' . $_SERVER['HTTP_HOST']); // 无效
    //setcookie('php_dbgs6_abc', '121111ie', time() + 24 * 3600, '/', $_SERVER['HTTP_HOST']); // 无效
    setcookie('php_dbgs6_abc', '121111ie', time() + 24 * 3600, '/'); // 有效
    print_r($_COOKIE);
    ?>
    <a href="s2.php">S2</a>
    s2.php<?php
    setcookie('php_dbgs6_abc', '', time() - 24 * 3500);
    print_r($_COOKIE);
    ?>
    <a href="s1.php">S1</a>
    上述几种方式看看究竟是哪里出了问题。