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
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
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.