-1

I am trying to change the session time in my login code, and here is the code I want to change the session time in:

<?php
if(session_id()==='')
{
session_start();
}
if(!(isset($_SESSION['status']) && $_SESSION['status'] == "logged_in"))
{
die("sorry, you must be logged in to view this page");
} else {
?>

How would I go about changing the session time? Also, if you can't change the session time in this, is there any code that can replace this and still work the same?

  • have you tried changing the session time in the php.ini file? Using PHP code, you could do something like this: ini_set('session.gc_maxlifetime', 3600); – Erick Apr 13 '15 at 01:54
  • 1
    `session_id()` must be at the top of *every* page when you want to use sessions. Not just when there is no session ID. So `if(session_id()==='') { session_start(); }` should just be `session_start();` – John Conde Apr 13 '15 at 01:56
  • Have you look at this http://stackoverflow.com/questions/8311320/how-to-change-the-session-timeout-in-php?rq=1 ? – Ôrel Apr 13 '15 at 02:48
  • I am wanting to change the session for an exclusive page, not just the login page – Levistobeavis Apr 13 '15 at 02:50
  • does it have to be a session? maybe you could do it in a cookie. as cookies life cycle can be edited easily. – Gokigooooks Apr 13 '15 at 03:48

1 Answers1

0

You may try session_cache_expire

session_cache_expire(30);
$cache_expire = session_cache_expire();

or see this

Community
  • 1
  • 1
Val
  • 63
  • 9