destroy cookie error

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
hame22
Forum Contributor
Posts: 214
Joined: Wed May 11, 2005 5:50 am

destroy cookie error

Post by hame22 »

Hi i am having trouble destroying a cookie

the cookie is set up as so:

Code: Select all

setcookie("fenmanactivities[username]", $username, $time + 3600);
				setcookie("fenmanactivities[password]", $password, $time + 3600);

and i am trying to destroy it like so but with no success:

Code: Select all

if (isset($_COOKIE['fenmanactivities']))
{
	
	$time = time();
	setcookie("fenmanactivities[username]","" , $time - 3600);
	setcookie("fenmanactivities[password]","" , $time - 3600);
	
	
}

any ideas as to what i am doing wrong?

thanks
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

you may want to set the time much farther back.. like a month. However, actual deletion of the cookie is entirely up to the browser, you're simply making a request that it does one.
User avatar
raghavan20
DevNet Resident
Posts: 1451
Joined: Sat Jun 11, 2005 6:57 am
Location: London, UK
Contact:

Post by raghavan20 »

your code looks alright but I have a doubt whether you did the same as when you tried to destroy the cookie

Code: Select all

$time = time();
setcookie("fenmanactivities[username]", $username, $time + 3600); 
                setcookie("fenmanactivities[password]", $password, $time + 3600);
are you sure its inside the if block???
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

forgot to mention, if your destruction cookie doesn't match the name, path, domain, and security flag of the previous one, it won't affect it.
User avatar
raghavan20
DevNet Resident
Posts: 1451
Joined: Sat Jun 11, 2005 6:57 am
Location: London, UK
Contact:

Post by raghavan20 »

setcookie("fenmanactivities[username]", $username, $time + 3600);
setcookie("fenmanactivities[password]", $password, $time + 3600);
anybody tell me how this works, fenmanactivities[username], fenmanactivities[password] :roll:
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

they are two different cookie names, nothing more.
User avatar
raghavan20
DevNet Resident
Posts: 1451
Joined: Sat Jun 11, 2005 6:57 am
Location: London, UK
Contact:

Post by raghavan20 »

is a variable in any of these forms legal???
fenmanactivities[username], fenmanactivities[password]

does not look like an array, an associative, then the key should be in quotes???
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

have a read here for an explanation of correct variable-string syntaxes..
User avatar
raghavan20
DevNet Resident
Posts: 1451
Joined: Sat Jun 11, 2005 6:57 am
Location: London, UK
Contact:

Post by raghavan20 »

that was an interesting doc, I am not really used to curly braces wrapping variables and arrays.
can you point out instances where the curly syntax is best for use??
Is it best for use for displaying multi-dimensional and class variables???
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

if you must (haha) use a variable inside a string, curly braces are always a best use. This is because you are helping PHP determine where the variable components start and end, so it takes less time to process.
Post Reply