Forum Moderators: coopster

Message Too Old, No Replies

Session

         

Oldsoldier

10:10 am on Jan 9, 2015 (gmt 0)

10+ Year Member



Please how can i help me create a session timeout with a function.

This script is the script i want to convert into a session.
session_start();

$expireAfter = 30;

if(isset($_SESSION['last_action'])){

$secondsInactive = time() - $_SESSION['last_action'];

//Convert our minutes into seconds.
$expireAfterSeconds = $expireAfter * 60;

//Check to see if they have been inactive for too long.
if($secondsInactive >= $expireAfterSeconds){
//User has been inactive for too long.
//Kill their session.
session_unset();
session_destroy();
}

}

$_SESSION['last_action'] = time();

<?php
class Session{

public static function exists($name){
return (isset($_SESSION[$name])) ? true : false ;
}

public static function put($name, $value){
return $_SESSION [$name] = $value;
}

public static function get($name){
return $_SESSION[$name];
}

public static function delete($name) {
if(self::exists($name)){
unset($_SESSION[$name]);
}
}

public static function activity($name) {
if(self::exists($name)){
unset($_SESSION[$name]);
}
}

public static function flash($name, $string = ''){
if(self::exists($name)){
$session = self::get($name);
self::delete($name);
return $session;
} else {
self::put($name, $string);
}

}
}

coopster

5:17 pm on Jan 15, 2015 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Any type of custom session handling will require some in-depth reading and understanding of how it all works in PHP. I would recommend beginning with the manual pages on this particular section.
[php.net...]