PHP Classes

File: php/isSessionTimeOut.php

Recommend this page to a friend!
  Classes of bamigboye biodun   Logical Functions   php/isSessionTimeOut.php   Download  
File: php/isSessionTimeOut.php
Role: Auxiliary script
Content type: text/plain
Description: Auxiliary script
Class: Logical Functions
General-purpose PHP and JavaScript functions
Author: By
Last change:
Date: 1 year ago
Size: 984 bytes
 

Contents

Class file image Download
<?php

function isSessionTimeOut(Int $minutes=5): Bool{
$timeout = $minutes * 60;
$fingerprint = hash_hmac('sha256', $_SERVER['HTTP_USER_AGENT'], hash('sha256', $_SERVER['REMOTE_ADDR'], true));
if(
session_id()==''){return true;}
if(!isset(
$_SESSION['last_active']) ){
   
$_SESSION['last_active'] = time();
   
$_SESSION['fingerprint'] = $fingerprint;
    return
false;
}

if ( (isset(
$_SESSION['last_active']) && (time() > ($_SESSION['last_active']+$timeout)))
   || (isset(
$_SESSION['fingerprint']) && $_SESSION['fingerprint']!=$fingerprint)) {
    return
true;
}else{

   
session_regenerate_id();
   
$_SESSION['last_active'] = time();
   
$_SESSION['fingerprint'] = $fingerprint;
  return
false;
}

      }

/*

Author : Biodun Bamigboye

This function recieves an arguments of the no of minutes you want to keep session alive
The default is 5 Minutes
returns false if session is still active
returns true if session has timed out or
There is change in user signature

*/