0

hi i use cookies in my site
setcookie("user","id-pass",time()+(60*60*24));
it work well
but when i try to logout
make
setcookie('user', '', time() -(60*60*24));
its not work
iam tried
setcookie('user', ' ', time() -(60*60*24));
not work
tried
unset($_COOKIES)
not work
tried replace it not work too
iam tried every thing

3
Contributors
7
Replies
8
Views
7 Years
Discussion Span
Last Post by click here
0

Try this:

setcookie('user','',(time()-(60*60*24)));

Also make sure that code is before any html output.

0

Ok i did some research on cookies and made a example script so you can see how to set, unset, and change value of cookies:

<?php
/* Name of script: cookietest.php
 * Description: shows how to (un)set cookies
 * Last edited: 12 septembre 2009
 * Made by Graphix
*/
setcookie('status','', time()+3600);
/* Changes value into FALSE if the falsebutton is clicked */
if ($_POST['falsecookie']) {
$_COOKIE['status'] = "FALSE";
}
/* Changes value into TRUE if the truebutton is clicked */
if ($_POST['truecookie']) {
$_COOKIE['status'] = "TRUE";
}
/* Unsets value into "" if the nobutton is clicked and then deletes cookie */
if ($_POST['nocookie']) {
$_COOKIE['status'] = "";
setcookie('status','', time()-3600);
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Test</title>
</head>
<body>
<div align='center'>
<?php
/* Shows the value of the 'status'-Cookie */
echo "Cookiestatus: ".$_COOKIE['status']."<br /><br />";
?>
<form action='cookietest.php' method='post'>
<input type="submit" name='truecookie' value='Set cookie TRUE' />
<input type="submit" name='falsecookie' value='Set cookie FALSE' /><br />
<input type="submit" name='nocookie' value='Set cookie empty' />
</form>
</div>
</body>
</html>

Use this script on your own localhost and see how it works, then adapt it to your personal script

~Graphix

Edited by Graphix: n/a

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.