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
hame22
Forum Contributor
Posts: 214 Joined: Wed May 11, 2005 5:50 am
Post
by hame22 » Fri Aug 19, 2005 8:44 am
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
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Fri Aug 19, 2005 8:49 am
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.
raghavan20
DevNet Resident
Posts: 1451 Joined: Sat Jun 11, 2005 6:57 am
Location: London, UK
Contact:
Post
by raghavan20 » Fri Aug 19, 2005 8:52 am
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???
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Fri Aug 19, 2005 9:00 am
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.
raghavan20
DevNet Resident
Posts: 1451 Joined: Sat Jun 11, 2005 6:57 am
Location: London, UK
Contact:
Post
by raghavan20 » Fri Aug 19, 2005 9:00 am
setcookie("fenmanactivities[username]", $username, $time + 3600);
setcookie("fenmanactivities[password]", $password, $time + 3600);
anybody tell me how this works, fenmanactivities[username], fenmanactivities[password]
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Fri Aug 19, 2005 9:04 am
they are two different cookie names, nothing more.
raghavan20
DevNet Resident
Posts: 1451 Joined: Sat Jun 11, 2005 6:57 am
Location: London, UK
Contact:
Post
by raghavan20 » Fri Aug 19, 2005 9:08 am
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???
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Fri Aug 19, 2005 9:12 am
have a read
here for an explanation of correct variable-string syntaxes..
raghavan20
DevNet Resident
Posts: 1451 Joined: Sat Jun 11, 2005 6:57 am
Location: London, UK
Contact:
Post
by raghavan20 » Fri Aug 19, 2005 11:11 am
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???
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Fri Aug 19, 2005 4:36 pm
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.