...

View Full Version : setting a cookie with php..



mia_tech
08-08-2008, 10:08 AM
I've been trying to set a cookie, and so far unsuccessful, every time I visit the page I open cookie editor addon in firefox and I don't see the cookie, here's what I'm using to set the cookie


setcookie("site_user", $u_name, date() + 31536000, "/");

could anyone advise if this is the correct way to do this?

thanks

www.pctechtips.org

Iszak
08-08-2008, 10:16 AM
Because you're using "date()" and not "time()"
e.g.


setcookie("site_user", $u_name, time() + 31536000, "/");

plus I'm pretty sure "/" is on by default.

Edit: And if $u_name isn't defined the cookie won't be set.. so ensure it's set.

mia_tech
08-08-2008, 08:19 PM
Because you're using "date()" and not "time()"
e.g.


setcookie("site_user", $u_name, time() + 31536000, "/");

plus I'm pretty sure "/" is on by default.

Edit: And if $u_name isn't defined the cookie won't be set.. so ensure it's set.

you hit it right on the head!... I don't know what made me use date() instead of time(), but as soon as I changed it... it worked!

thanks

mia_tech
08-08-2008, 08:29 PM
in my cookie code I'm setting the name of the cookie to equal the username; how could generate an md5 hash of this username instead of just put the plain text of the username in the cookie?...

thanks


www.pctechtips.org

Nightfire
08-08-2008, 09:26 PM
setcookie("site_user", md5($u_name), time() + 31536000, "/");

mia_tech
08-08-2008, 09:47 PM
thanks



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum