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);
精彩评论