need the right way to setcookie in wordpress

Posted by jq beginner on Stack Overflow See other posts from Stack Overflow or by jq beginner
Published on 2012-09-12T17:24:58Z Indexed on 2012/10/02 21:37 UTC
Read the original article Hit count: 90

Filed under:
|
|

i've been looking the whole day how to setcookies in wordpress. in my way i found out (using the developer toolbar) that the cookie is set but still not working. i have 2 files the first contains the login form redirecting to another page to set the cookie and return to another page to check if it's working. domain which is tested on is like this : blog.mydomain.com. here's the setcookie file :

<?php
setcookie("user_name","test",time()+3600);
?>

and chcking the cookie like this :

if(isset($_COOKIE["user_name"])){
echo "cookie exists";
}
else{
echo "cookie doesn't exist";
}

i've read many topics about this issue but there was no clear answer. Thanks in advance

© Stack Overflow or respective owner

Related posts about Wordpress

Related posts about cookies