Hi,
I'm having trouble updating a cookie value.
I'm setting the cookie as such:
setcookie("UserName",$_SESSION['UserName'],time() + 2592000,"/","www.mydomain.com",1);
This occurs at the top of the script page where a user ends up after logging in. $SESSION['UserName'] is set in a "process_login" controller script. The purpose of the cookie is simply to auto-fill-in the UserName field when they come back to the login page. I'm trying to handle the case where multiple users may be logging in from the same computer. Upon a second login, followed by a "logout", the first username still displays in the UserName textbox on the login page (retrieved from the cookie) - even after refreshing the page.
The code on the login page to retrieve the cookie is:
value="<?php
if(isset($COOKIE["UserName"])){
echo $_COOKIE["UserName"];
}
?>"
I assumed calling setcookie again would overwrite the value set the first time. As an alternative to just having the setcookie code, I tried the following, thinking that in order to update a cookie value maybe you need to set the variable value directly, ie $_COOKIE['UserName'] (but didn't work):
if(!isset($COOKIE['UserName'])){
setcookie("UserName",$SESSION['UserName'],time() + 2592000,"/","www.mydomain.com",1);
}else{
$COOKIE['UserName']=$SESSION['UserName'];
}
I guess my main problem is just that I don't understand how to update a cookie.
thanks for any suggestions