Web Hosting Talk







View Full Version : setcookie question


Joshua44
05-04-2003, 11:58 AM
I've been using the following code for setting cookies:

setcookie("name", "value", time()+666, "/", $_SERVER['SERVER_NAME'], 0);

This works on my site but not on my computer.
I recently changed it to

setcookie("name", "value", time()+666, "/", "", 0);

and it works. I've tested it on Xitami and Apache 1.3.77.
Any comments?

aleck
05-04-2003, 12:09 PM
what's the value of $_SERVER['SERVER_NAME'] on your computer?

Joshua44
05-04-2003, 01:18 PM
localhost

I tried "http://localhost" and it still doesn't work.

MarkIL
05-04-2003, 01:38 PM
"localhost" is not technically a domain name. Hence, it will not work As It Should(tm).

Try adding "localhost.localdomain" into your HOSTS file and using "localhost.localdomain" as the domain parameter to setcookie().

Joshua44
05-04-2003, 01:47 PM
where's the HOSTS file?

MarkIL
05-04-2003, 01:50 PM
On Windows, in %windir%\system32\drivers\etc

IIRC.

aleck
05-05-2003, 04:20 AM
i would use this one istead:

setcookie("name", "value", time()+666, "/", ($_SERVER['SERVER_NAME']=="localhost")?"":$_SERVER['SERVER_NAME']), 0);