Jump to content

[SOLVED] find out the time that a session was set?


bobinindia

Recommended Posts

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

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.