bobinindia Posted April 15, 2008 Share Posted April 15, 2008 Is it possible to find out what time a session was set? My intention is to use a different session value depending upon which one was set most recently. Quote Link to comment Share on other sites More sharing options...
benphp Posted April 15, 2008 Share Posted April 15, 2008 I don't think you can get that info without saving it in a cookie or db somewhere. You could save the session and session_time in a cookie or db, then fetch that data and run your code. Quote Link to comment Share on other sites More sharing options...
rhodesa Posted April 15, 2008 Share Posted April 15, 2008 Not to my knowledge. But, you could use an include file to start the session like: <?php session_start(); if(!isset($_SESSION['time_started'])) $_SESSION['time_started'] = time(); ?> Then, at the top of your all your scripts, include that file. After that, you can refer to $_SESSION['time_started'] for the time the session was started Quote Link to comment Share on other sites More sharing options...
bobinindia Posted April 16, 2008 Author Share Posted April 16, 2008 Thank you both. That is fine for my needs. Quote Link to comment Share on other sites More sharing options...
discomatt Posted April 16, 2008 Share Posted April 16, 2008 just define all your session variables like this <?php function set_session_var ($varname, $value) { if ( !isset($_SESSION[$varname]) ) { $_SESSION[$varname] = $value; $_SESSION['_TIME_STARTED'][$varname] = time(); } else $_SESSION[$varname] = $value; } function get_time_set ($varname, $date_format = FALSE) { if ( !isset($_SESSION['_TIME_STARTED'][$varname]) ) return FALSE; if ( $date_format ) return date( $date_format, $_SESSION['_TIME_STARTED'][$varname] ); else return $_SESSION['_TIME_STARTED'][$varname]; } function get_newest_var_name () { if ( !is_array($_SESSION['_TIME_STARTED']) ) return FALSE; $holder = $_SESSION['_TIME_STARTED'] arsort($holder); reset($holder); // May be unnecessary, too lazy to check right now return key($holder); } ?> Keeps track of their creation date for you Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.