Unable to delete cookie - please help

Hi, I am just trying to remove a couple of cookies set elsewhere on the site, but I can’t seem to get it going.

Here’s how I set my cookies:

// Set Cookie
	setcookie ('USERNAME', $_POST['username'],0,'/');
	setcookie ('PASSWORD', $_POST['password'],0,'/');

and this is my current code for trying to remove them:

// Destroy Sessions
	setcookie ('USERNAME', '', time()-2419200);
	setcookie ('PASSWORD', '', time()-2419200);	

But when I load a test page with:

        echo $_COOKIE['PASSWORD'];     

I still get the cookie values.

I have tried several different combinations of removal including these:

setcookie ('USERNAME', '', time()-3600);
setcookie ('USERNAME', '',1);
setcookie ('USERNAME', '',0);

but still no luck

Can anyone shed any light on this?

Many thanks


Glad that you found the solution. Good job. :slight_smile:

Thread closed.

Ok, I posted too soon.

I realised that the code to set it blank must have the same arguments as the code to set it in the first place.

This worked for me:

to set:

setcookie ('USERNAME', $_POST['username'],0,'/');
setcookie ('PASSWORD', $_POST['password'],0,'/');

and to remove:

setcookie ('USERNAME', '',0,'/');
setcookie ('PASSWORD', '',0,'/');