setcookie("severss", "ss",$num, '/','localhost');
SetCookie("sever","dd",$num,"/","127.0.0.1")
两个setcookie都成功!
但是用localhost的那个在localhost域名下就不可以访问
而127.0.0.1在127.0.0.1下能访问
这是为什么阿?
要怎么写才能在localhost下设置cookie成功呢?
怎样在http://localhost/kongjian/admin.php/account/login下设置cookie然后在http://localhost/kongjian/下边也可以访问到?

解决方案 »

  1.   

    something that wasn't made clear to me here and totally confused me for a while was that domain names must contain at least two dots (.), hence 'localhost' is invalid and the browser will refuse to set the cookie! instead for localhost you should use false.to make your code work on both localhost and a proper domain, you can do this:<?php$domain = ($_SERVER['HTTP_HOST'] != 'localhost') ? $_SERVER['HTTP_HOST'] : false;
    setcookie('cookiename', 'data', time()+60*60*24*365, '/', $domain, false);
    //手册的内容,建议,没事多翻翻手册
    ?> 
      

  2.   

    恩,尤其是在线手册
    http://www.php.net/manual/en/function.setcookie.php上面有很多用户提交的注释,使用的心得和使用中碰到的问题的解决方法。