By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,616 Members | 1,198 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,616 IT Pros & Developers. It's quick & easy.

How to set a session cookie with a path?

P: n/a
I need to set a session cookie (expires when the browser closes) with a
path of "/".

Is there a way to do it?

I tried:

setcookie("cookie_name", $cookie_value, "", "/");

and

setcookie("cookie_name", $cookie_value, "0", "/");

and of course none of them worked.

I can't move the page that is setting the cookie to the top level
directory of the site, but I need the cookie to be available to couple
of page there.

Is this doable at all?

TIA

Jul 20 '06 #1
Share this Question
Share on Google+
2 Replies


P: n/a
John Drako wrote:
I tried:

setcookie("cookie_name", $cookie_value, "", "/");

and

setcookie("cookie_name", $cookie_value, "0", "/");

and of course none of them worked.
The manual says:

"Because the expire argument is integer, it cannot be skipped with an empty
string, use a zero (0) instead"

So, do not use "0" but 0.

When working between subdomains of the same father domain, you should also
supply the fifth argument with a value of ".yourdomain.com" (mind the
preceding dot).
JW
Jul 20 '06 #2

P: n/a
On Thu, 20 Jul 2006 16:29:10 -0400, Janwillem Borleffs wrote
(in article <44***********************@news.euronet.nl>):
John Drako wrote:
>I tried:

setcookie("cookie_name", $cookie_value, "", "/");

and

setcookie("cookie_name", $cookie_value, "0", "/");

and of course none of them worked.

The manual says:

"Because the expire argument is integer, it cannot be skipped with an empty
string, use a zero (0) instead"

So, do not use "0" but 0.
Thanks. I don't know how I missed that.

Jul 22 '06 #3

This discussion thread is closed

Replies have been disabled for this discussion.