开发者

Create unset cookie button

开发者 https://www.devze.com 2023-02-13 18:15 出处:网络
I have created a cookie using php and now I need to create a button the user can click to log out. This would be the php code to unset the cookie:

I have created a cookie using php and now I need to create a button the user can click to log out.

This would be the php code to unset the cookie:

 unset($_COOKIE['access_token']);  

But I'm a quite stuck with how to make the button functionality. Can anyone help me with开发者_Go百科 it?

Thanks a lot


if(isset($_GET['logout'])) {

unset($_COOKIE['access_token']);

header('Location: /');

exit;

}

on site

<a href="?logout">logout</a>


By the way you can delete cookie by setting time in past

setcookie($_COOKIE['access_token'],'',time()-3600);

you should unset session

session_destroy()'


It's actually best to do:

setcookie("myCookie", null, 1); //# This will expire / delete *immediately*

If you use

setcookie("myCookie", null, 0), the cookie is still valid until they close their browser.
0

精彩评论

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