so I'm looking at the PHP docs for setcookie and this is what I see:

bool setcookie ( string name [, string value [, int expire [, string path [, string domain [, bool secure]]]]] )

they say if you want to have the cookie expire when the browser closes then do something like this:
setcookie("TestCookie", $value);

But I want this cookie to work on several subdomains no I need to fill in the domain part... is there any way around this in PHP?

If you do not require the cookie to set on a computer/browser for certain length of time (few hours to few months), you can simply use session. Session is a safer option as some browsers block cookies. By the end of a session, use unset to remove the session value. Sessio will end automatically when the browser closed.

The values in [ ] in the function are optional, but if you want to skip one you need to put a placeholder value in, along the lines of:

setcookie("TestCookie", $value,'','/','domain.com');

The values in [ ] in the function are optional, but if you want to skip one you need to put a placeholder value in, along the lines of:

setcookie("TestCookie", $value,'','/','domain.com');

The above code will not work. Try this:

setcookie($cookieName, $cookieValue, NULL, $path, $domain);

You can read more tutorials on Cookies at: http://www.herongyang.com/php/cookie.html

--Mark

Exactly right, sorry, my bad. The expires value is the only non-string value, and so must be set to either null or 0 (zero), which will expire the cookie when the session ends.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.