Page 1 of 1
destroy cookie error
Posted: Fri Aug 19, 2005 8:44 am
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
Posted: Fri Aug 19, 2005 8:49 am
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.
Posted: Fri Aug 19, 2005 8:52 am
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???
Posted: Fri Aug 19, 2005 9:00 am
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.
Posted: Fri Aug 19, 2005 9:00 am
by raghavan20
setcookie("fenmanactivities[username]", $username, $time + 3600);
setcookie("fenmanactivities[password]", $password, $time + 3600);
anybody tell me how this works, fenmanactivities[username], fenmanactivities[password]

Posted: Fri Aug 19, 2005 9:04 am
by feyd
they are two different cookie names, nothing more.
Posted: Fri Aug 19, 2005 9:08 am
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???
Posted: Fri Aug 19, 2005 9:12 am
by feyd
have a read
here for an explanation of correct variable-string syntaxes..
Posted: Fri Aug 19, 2005 11:11 am
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???
Posted: Fri Aug 19, 2005 4:36 pm
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.