PHPSESSID expires before my cookie

This is a discussion on PHPSESSID expires before my cookie within the PHP Language forums, part of the PHP Programming Forums category; I have the following code: $expireTime = 60*60*24*364; // 365 days session_set_cookie_params($expireTime); // seconds session_start(); My problem is, that ...


Go Back   Usenet Forums > PHP Programming Forums > PHP Language

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 04-29-2005
FamB
 
Posts: n/a
Default PHPSESSID expires before my cookie

I have the following code:

$expireTime = 60*60*24*364; // 365 days
session_set_cookie_params($expireTime); // seconds
session_start();

My problem is, that my PHPSESSID expires before my cookie. I have then
added the fowlloing code:

$expireTime = 60*60*24*364; // 365 days
session_set_cookie_params($expireTime); // seconds
session_cache_limiter('private');
session_cache_expire(8760); // minutes
session_start();

Now my cookie expires after the browser closes instead of the 365 days!?

How do I get the same expiration on both my cookie and my PHPSESSID on
my server?

I am running with PHP5 on a FreeBSD server.
Reply With Quote
  #2 (permalink)  
Old 05-01-2005
FamB
 
Posts: n/a
Default Re: PHPSESSID expires before my cookie

> How do I get the same expiration on both my cookie and my PHPSESSID on
> my server?


No one that knows anything about it? I have tried a few thing, but I
can't get it working.
Reply With Quote
  #3 (permalink)  
Old 05-02-2005
Mladen Gogala
 
Posts: n/a
Default Re: PHPSESSID expires before my cookie

On Sun, 01 May 2005 02:39:24 +0200, FamB wrote:

>
> No one that knows anything about it? I have tried a few thing, but I
> can't get it working.


OK. What are the few things that you tried? What exactly do you want?
You want your PHPSESSID cookie to survive closing the browser, thus in
effect establishing a permanent session.

You are using PHP5. PHP5 has a parameter called session.cookie_lifetime.
Here is an explanation taken from the INI file.

; Lifetime in seconds of cookie or, if 0, until browser is restarted.
session.cookie_lifetime = 0


By the way, session cannot live longer then your browser. Once you
close your browser, your session is closed. The session_start()
function will start a new session. HTTPD is a stateless protocol.
You cannot trick it into allowing you permanent connection. It would be
nice, but no way to do that.



--
Egoist: A person of low taste, more interested in themselves than in me.

Reply With Quote
  #4 (permalink)  
Old 05-02-2005
Nicholas Sherlock
 
Posts: n/a
Default Re: PHPSESSID expires before my cookie

Mladen Gogala wrote:
> By the way, session cannot live longer then your browser. Once you
> close your browser, your session is closed. The session_start()
> function will start a new session. HTTPD is a stateless protocol.
> You cannot trick it into allowing you permanent connection. It would be
> nice, but no way to do that.


Um. As you say, HTTP is a stateless protocol. That means that as far as
the server is concerned, closing a browser window does absolutely
nothing! It all hinges on whether or not *your browser* will send the
session cookie back to the server again when reopened. This is easy!
Just set your cookie's expiry date to some date years in the future (It
is a session only cookie by default), and your browser will send it back
to the server next time it visits.

Cheers,
Nicholas Sherlock
Reply With Quote
  #5 (permalink)  
Old 05-02-2005
FamB
 
Posts: n/a
Default Re: PHPSESSID expires before my cookie

> You are using PHP5. PHP5 has a parameter called session.cookie_lifetime.
> Here is an explanation taken from the INI file.
>
> ; Lifetime in seconds of cookie or, if 0, until browser is restarted.
> session.cookie_lifetime = 0


Okay, I thought it was something that could be set in the PHP code but I
have now changed the value in my php.ini and that seems to solve the
problem. Thanks.
Reply With Quote
  #6 (permalink)  
Old 05-03-2005
FamB
 
Posts: n/a
Default Re: PHPSESSID expires before my cookie

> You are using PHP5. PHP5 has a parameter called session.cookie_lifetime.
> Here is an explanation taken from the INI file.
>
> ; Lifetime in seconds of cookie or, if 0, until browser is restarted.
> session.cookie_lifetime = 0


Okay, perhaps I am mixing sessions and cookies together because I can
not get it working as I want.

I have this code:

if($autologin == "on")
{
$expireTime = 60*60*24*364; // 365 days
session_set_cookie_params($expireTime); // seconds
}
else
{
$expireTime = 0; // when browser closes
session_set_cookie_params($expireTime); // seconds
}
session_start();

"autologin" is a checkbox, to let the user have a permanent session.

What I want is, to set the client cookie to either 365 days or to die
when the browser closes.
I would prefer if the server session (PHPSESSID) expired at the same
time as the client cookie, but if that is not possible, then it should
just be 365 days.
Right now I have set "session.cookie_lifetime = 31536000" in my php.ini
and then this above code.

Can anyone help - either to let me understand what I am missing or with
an example?
Reply With Quote
  #7 (permalink)  
Old 05-04-2005
FamB
 
Posts: n/a
Default Re: PHPSESSID expires before my cookie

>> You are using PHP5. PHP5 has a parameter called session.cookie_lifetime.
>> Here is an explanation taken from the INI file.
>>
>> ; Lifetime in seconds of cookie or, if 0, until browser is restarted.
>> session.cookie_lifetime = 0

>
> Okay, perhaps I am mixing sessions and cookies together because I can
> not get it working as I want.
>
> I have this code:
>
> if($autologin == "on")
> {
> $expireTime = 60*60*24*364; // 365 days
> session_set_cookie_params($expireTime); // seconds
> }
> else
> {
> $expireTime = 0; // when browser closes
> session_set_cookie_params($expireTime); // seconds
> }
> session_start();
>
> "autologin" is a checkbox, to let the user have a permanent session.
>
> What I want is, to set the client cookie to either 365 days or to die
> when the browser closes.
> I would prefer if the server session (PHPSESSID) expired at the same
> time as the client cookie, but if that is not possible, then it should
> just be 365 days.
> Right now I have set "session.cookie_lifetime = 31536000" in my php.ini
> and then this above code.
>
> Can anyone help - either to let me understand what I am missing or with
> an example?


I still have my problems with this. I hope there to be a solution for
it? :-)
Reply With Quote
  #8 (permalink)  
Old 05-15-2005
R. Rajesh Jeba Anbiah
 
Posts: n/a
Default Re: PHPSESSID expires before my cookie

FamB wrote:
<snip>
> I still have my problems with this. I hope there to be a solution for


> it? :-)


Probably, it might be your session gc setting that trashes your
session.

--
<?php echo 'Just another PHP saint'; ?>
Email: rrjanbiah-at-Y!com Blog: http://rajeshanbiah.blogspot.com/

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 11:07 AM.


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