开发者

how can i define a cookie global?

i defined a cookie in a page like check.php and set it.

setcookie("u","blue",time() + 3600);

now i want to check that if it is set or no in another page开发者_运维技巧 like index.php.

i sure that cookie is set in check.php but when i check that in index.php with this code:

if( isset($_COOKIE["u"] ) )
  {
        echo "correct";
  } 

it doesn't worked!!and if doesn't run? what is problem?if cookies worked only in that page that it defined?

Edit:

i change it to setcookie("u","blue",time() + 3600,'/', 'www.example.vcn.ir'); but has same problem.


Update:

Set the domain to NULL or FALSE as your working on localhost.

Try setting the cookie path and domain.

setcookie ("u", 'blue', time()+3600, '/', NULL, 0 );  

Try var_dumping $_COOKIE to see whats in it..

var_dump($_COOKIE);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜