how to change session time

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
php_dev1
Forum Newbie
Posts: 5
Joined: Wed Jun 18, 2008 8:05 am

how to change session time

Post by php_dev1 »

hello,
i want to change session time.the session time should differ according to section of my module.
i have tried with this function ini_set('session.gc_maxlifetime'),but then also its not happening.

please help me.
thanks in advance
nowaydown1
Forum Contributor
Posts: 169
Joined: Sun Apr 27, 2008 1:22 am

Re: how to change session time

Post by nowaydown1 »

I believe you actually want session.cookie_lifetime:

Code: Select all

 
ini_set( 'session.cookie_lifetime', 3600 * 24 );
 
WebbieDave
Forum Contributor
Posts: 213
Joined: Sun Jul 15, 2007 7:07 am

Re: how to change session time

Post by WebbieDave »

These are the settings that affect session length:

ini_set('session.cache_expire', (string)EXPIRE_LENGTH);
ini_set('session.gc_maxlifetime', (string)SESSION_LENGTH);
session_set_cookie_params(SESSION_LENGTH);

In addition to these, if you're on a shared server, your host may periodically empty the shared php sessions directory. To avoid this, if necessary, you can store sessions in alternate directory with:

session_save_path(SAVE_PATH);
php_dev1
Forum Newbie
Posts: 5
Joined: Wed Jun 18, 2008 8:05 am

Re: how to change session time

Post by php_dev1 »

i have tried with these finction ini_set('session.gc_maxlifetime',7200),session_cache_expire( 5)
but nothing is happening...
in my proj,in all my modules session time upto 24 that one is default from php.ini file.but now for another module i want session time should be 8 hours...so what i have to do?

this is my code:
1.session_start();
$inactive = 28800;
if(isset($_SESSION['start']) ) {
$session_life = time() - $_SESSION['start'];
print_r($session_life);
if($session_life > $inactive){
session_cache_expire( 28800);
session_destroy();
header("Location: ems_home.php?<?= getSidParam($sid) ?>&ACTION=log_out_user");
}
}
$_SESSION['start'] = time();

2.$garbaze="28800";
ini_set('session.gc_maxlifetime',$garbaze);

$_SESSION['timeout'] =ini_get('session.gc_maxlifetime');

i am not getting what is wrong in my code...
plz help.....
php_dev1
Forum Newbie
Posts: 5
Joined: Wed Jun 18, 2008 8:05 am

Re: how to change session time

Post by php_dev1 »

even i have tried with sesstion cookie using this function setcookie("TestCookie", $orgInfo[3], time()+28800);
...then also it's not happening...whwether we can use session & cookie in one page?

help me......
Post Reply