PHP/Cookie

software development

#1

i’m using PHP throughout my pages… I can create a cookie, but for some reason it won’t let me delete them.

I’m using this for a login/logout situation…

here is some of my code:

setcookie(“AcctInfo[username]”, $username, time()+60*3, “/directory/”, “.mydomain.com”);

setcookie(“AcctInfo[password]”, $password, time()+60*3, “/directory/”, “.mydomain.com”);

The above code sets the cookie fine and it expires it if you stay logged on too long. (I changed the domain and folders for security reasons).

Then when I try to delete the cookie it doesn’t work. I tried the following below:

setcookie(“AcctInfo”);
or
setcookie(“AcctInfo[‘username’]”);

Thanks in advance for your help.

www.iboostdaily.com


#2

You need to include all of the information you put into your cookie when you initially set it. So if your cookie were set using:
setcookie(“AcctInfo[username]”, “$username”, time+60, “/directory/”, “.mydomain.com”);

delete it using:

setcookie(“AcctInfo[username]”, “”, time-60, “/directory/”, “.mydomain.com”);

At least, the above works for my pages.

~Michelle


#3

oh ok, thanks… i’ll give it a shot to see if it works

edit: it works!!!