How to set a session cookie with a path?

This is a discussion on How to set a session cookie with a path? within the alt.comp.lang.php forums, part of the PHP Programming Forums category; I need to set a session cookie (expires when the browser closes) with a path of "/". Is there ...


Go Back   Usenet Forums > PHP Programming Forums > alt.comp.lang.php

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 07-20-2006
John Drako
 
Posts: n/a
Default How to set a session cookie with a path?

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

Reply With Quote
  #2 (permalink)  
Old 07-20-2006
Janwillem Borleffs
 
Posts: n/a
Default Re: How to set a session cookie with a path?

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


Reply With Quote
  #3 (permalink)  
Old 07-22-2006
John Drako
 
Posts: n/a
Default Re: How to set a session cookie with a path?

On Thu, 20 Jul 2006 16:29:10 -0400, Janwillem Borleffs wrote
(in article <44bfe793$0$76723$dbd49001@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.

Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT +1. The time now is 02:16 PM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0