Hi.
I'm working on a logout
function and if I use:
setcookie ("TestCookie", "", time() - 3600);
the logout doesn't work immediately
unless I don't refresh the page.
However if I use unset($COOKIE['TestCookie'])
it works fine without refresh.
I've never saw use unset with $COOKIE
and I'd like to know if I can use it
without troubles.
What do you think about ?
Take care.
Whisher.
[RESOLVED] By the way of Cookie and unset.
Sorry, I made a mistake ;]
I've never seen to use.
See you soon.
Whisher
If you use "unset()" then, yes, your server-stored cookie value will be unset, but to tell the user's browser to set or unset a cookie you need to use "setcookie()" or some other method that acts on the http response header. afaik
Code
function LogOut()
{
$this->uid=FALSE;
$this->ip=FALSE;
setcookie("authentication_Uid","",time()-$this->CookiesExpiry);
setcookie("authentication_Ip","",time()-$this->CookiesExpiry);
unset($COOKIE['authentication_Uid']);
unset($COOKIE['authentication_Ip']);
$this->authed=FALSE;
}
and I use like this
if($GET['kill'])
{
$auth->LogOut();
var_dump($COOKIE)
//if I only use setcookie() with var_dump I still get $COOKIE sets
}
What do you think about ?
Whisher
Take care.
Ps
What does afaik mean ?
out of curiosity ;] Bye !
If you use only "setcookie()" then, yes, var_dump will show the cookie as still set. But by then your http response to the page request will have caused the user's browser to expire the cookie. So on its next request the browser won't send that cookie. When you use "unset()" you merely erase, on your server, the cookie data that was sent by the browser in its request for the immediate page.
It looks to me like your function should work, and, on the next request, your user will not send the cookies and won't be authorized.
"afaik" = "as far as I know"
Thank you so much for the useful enlightment.
No end of thanks for the meaning of afaik ;]
Take care.
Whisher.