Jump to content

quick question


radiohomer

Recommended Posts

hey guys

 

i have a script that creates a cookie named "MyLoginPage"

 

now everything works well

the cookie is saved and it keeps the user logged in

 

The Question

ok so im wanting to create a link that will delete the cookie

so when the user clicks the link it will delete the cookie

 

is this possible??

if so, how??

 

many thanks

Link to comment
https://forums.phpfreaks.com/topic/236017-quick-question/
Share on other sites

yes its possible...

create a link add href wil be the file name which will delete that cookie

<a href="del_cookie.php">Click here to delete cookie</a>

 

and your del_cookie.php file will contain below code

 

<?php

  setcookie("user", "", time()-3600);

?>

 

Simple logic to delete cookie is just assign past time to the cookie :)

Link to comment
https://forums.phpfreaks.com/topic/236017-quick-question/#findComment-1213656
Share on other sites

yes its possible...

create a link add href wil be the file name which will delete that cookie

<a href="del_cookie.php">Click here to delete cookie</a>

 

and your del_cookie.php file will contain below code

 

<?php

  setcookie("user", "", time()-3600);

?>

 

Simple logic to delete cookie is just assign past time to the cookie :)

 

thank you ilovephp

i would also like to thank Paul for his comment below sent via PM this helped A LOT and is now working

 

make a link to a page logout.php

 

- logout.php

<?

if(setcookie ( string $name [, string $value [, int $expire = 0 [, string $path [, string $domain [, bool $secure = false [, bool $httponly = false ]]]]]] )){

echo 'All done';

}else{

echo 'Failed to log you out because you are most likely your not logged in.';

}

?>

 

And read http://php.net/manual/en/function.setcookie.php

Link to comment
https://forums.phpfreaks.com/topic/236017-quick-question/#findComment-1213701
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.