0

hi friend i use the following code for increment session on server host side as

ini_set('session.cookie_lifetime', 60 * 60 * 24 * 7);
ini_set('session.gc_maxlifetime', 60 * 60 * 24 * 7);
if(!isset($_SESSION)) 
session_start(); 

but the session is expire in 1440 seconds.

i use as the following code

var_dump(ini_set('session.cookie_lifetime', 60 * 60 * 24 * 7));
var_dump(ini_set('session.gc_maxlifetime', 60 * 60 * 24 * 7));

it returns as returns string(1) "0" string(4) "1440"

thanks and regards

kavita
  • 15
  • 6

2 Answers2

0

why don't you set it as constant number and input variable name? It would be easier for you to modified in the future also. Example :

var SESSION_MAX_LIFE = 60*60*24*7;
ini_set('session.cookie_lifetime', SESSION_MAX_LIFE );
ini_set('session.gc_maxlifetime', SESSION_MAX_LIFE );
if(!isset($_SESSION)) 
    session_start(); 

sorry if any syntax error cause I don't know much about PHP :).

Kai
  • 3,104
  • 2
  • 19
  • 30
0

For set the time life in php, you can use the function session_set_cookie_params, before the

session_start. here's a link to documentation for the function.

use it like this :

<?php
  $lifetime=7200; // this is set in seconds so, 7200 is 2 hours.
  session_set_cookie_params($lifetime,'/'); //the '/' parameter is set to let the session be 
                                           //used in all files in your current directory.
  session_start();
?>

in here is a more elaborate explanation on session lifetime and how to maintain it for hours or days.

Community
  • 1
  • 1
Gokigooooks
  • 794
  • 10
  • 20