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

Recommended Answers

All 7 Replies

Try this:

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

Also make sure that code is before any html output.

its not work too
thanks

The only other thing I can suggest is the following code:

setcookie('user','',0);

:'(
not work too

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

thanks i have found great code

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.