Editing SESSION lifetime
Moderator: General Moderators
- aceconcepts
- DevNet Resident
- Posts: 1424
- Joined: Mon Feb 06, 2006 11:26 am
- Location: London
Editing SESSION lifetime
Hi All,
Can anyone supply a definitive solution as to how one can edit (increase/decrease) SESSION lifetime?
Thanks.
Can anyone supply a definitive solution as to how one can edit (increase/decrease) SESSION lifetime?
Thanks.
Re: Editing SESSION lifetime
Using session_set_cookie_params() -
Code: Select all
function sessionLifetime($seconds) {
$cookieParams = session_get_cookie_params();
session_set_cookie_params(
$seconds,
$cookieParams['path'],
$cookieParams['domain'],
$cookieParams['secure']
);
}
- aceconcepts
- DevNet Resident
- Posts: 1424
- Joined: Mon Feb 06, 2006 11:26 am
- Location: London
Re: Editing SESSION lifetime
Hi pytrin,
Thanks for the snippet of code. This code will only work with cookies though right? I am primarily looking for a solution for $_SESSION max_life_time editing.
Thanks for the snippet of code. This code will only work with cookies though right? I am primarily looking for a solution for $_SESSION max_life_time editing.
Re: Editing SESSION lifetime
No, this is for sessions. Unless you are using session.use_cookies=0, every session created stores its session id using a cookie. Otherwise it must be passed through the URL, which modern applications try to avoid for security reasons.
Re: Editing SESSION lifetime
For this you have to overwrite the php.ini's value.
Cheers
Code: Select all
ini_set(’session.gc_maxlifetime’, ‘28800?);// Set maxlifetime to 4 hours- aceconcepts
- DevNet Resident
- Posts: 1424
- Joined: Mon Feb 06, 2006 11:26 am
- Location: London
Re: Editing SESSION lifetime
Yes, ini_set is what I have played about with but to no avail.pcoder wrote:For this you have to overwrite the php.ini's value.CheersCode: Select all
ini_set(’session.gc_maxlifetime’, ‘28800?);// Set maxlifetime to 4 hours
@pytrin: Thanks for the confirmation. I'm going to give it a whirl and see how it works.
@pcoder: Also thanks to you for your post. I will give this a try too.
Will post back soon.
- aceconcepts
- DevNet Resident
- Posts: 1424
- Joined: Mon Feb 06, 2006 11:26 am
- Location: London
Re: Editing SESSION lifetime
I've tried both pieces of coded posted however, it still doesn't work.
Re: Editing SESSION lifetime
Well obviously for each of us, our suggested method works. Maybe you should explain what exactly doesn't work, post the code you used, some details on your environment, etc.
- aceconcepts
- DevNet Resident
- Posts: 1424
- Joined: Mon Feb 06, 2006 11:26 am
- Location: London
Re: Editing SESSION lifetime
Yeh, sorry about blunt reply - i'm almost falling asleep at work
So this is how i'm testing it:
I tried the ini_set approach first.
I even get the session maxlifetime config setting to determine if it's been changed.
I have PHP 4.4.4 running on Apache (Unix)
So this is how i'm testing it:
I tried the ini_set approach first.
Code: Select all
ini_set(’session.gc_maxlifetime’, 3600);
$lifetime=ini_get('session.gc_maxlifetime');
session_start();
if(!isset($_SESSION['logged']))
{
echo '<p>Not set</p>';
}
echo "<p>$lifetime</p>";
$_SESSION['logged']=1;
I have PHP 4.4.4 running on Apache (Unix)
Re: Editing SESSION lifetime
And how are you testing it to see if it's working? where is it failing?
- aceconcepts
- DevNet Resident
- Posts: 1424
- Joined: Mon Feb 06, 2006 11:26 am
- Location: London
Re: Editing SESSION lifetime
Well from the above you can see that i get the session lifetime var as soon as i edit it.
Re: Editing SESSION lifetime
You're going to have to be more specific than that..
What is not working for you? are sessions not registering at all? or do they not last their set lifetime? what is the value that $lifetime var? try var_dump it instead of echoing it also.
What is not working for you? are sessions not registering at all? or do they not last their set lifetime? what is the value that $lifetime var? try var_dump it instead of echoing it also.
- aceconcepts
- DevNet Resident
- Posts: 1424
- Joined: Mon Feb 06, 2006 11:26 am
- Location: London
Re: Editing SESSION lifetime
Ok, i'll be more specific.
Sessions are working fine in terms of storing data etc... sessions expire after the default lifetime of 24min (1440 seconds).
The $lifetime var simply outputs the current session lifetime set in php.ini - see line 4 from my post.
Sessions are working fine in terms of storing data etc... sessions expire after the default lifetime of 24min (1440 seconds).
The $lifetime var simply outputs the current session lifetime set in php.ini - see line 4 from my post.
Re: Editing SESSION lifetime
.. and what is that value? is it not what you set before? did you try my suggested method? how did you test that? (since it doesn't change session.gc_maxlifetime)The $lifetime var simply outputs the current session lifetime set in php.ini - see line 4 from my post.
- aceconcepts
- DevNet Resident
- Posts: 1424
- Joined: Mon Feb 06, 2006 11:26 am
- Location: London
Re: Editing SESSION lifetime
$lifetime returned 1440.
I did try your suggested method but to no avail.
However, I have contacted my ISP and they tested it from their end and the ini_set method worked for them. They're currently looking into it.
I did try your suggested method but to no avail.
However, I have contacted my ISP and they tested it from their end and the ini_set method worked for them. They're currently looking into it.