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

Try this:


Also make sure that code is before any html output.

its not work too

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


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:

/* 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">
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<div align='center'>
/* 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' />

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


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.