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 ...
|
|||||||
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
|
|||
|
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. |
|
|||
|
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. |
|
|||
|
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 |
|
|||
|
> 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. |
|
|||
|
> 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? |
|
|||
|
>> 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? :-) |
|
|||
|
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/ |