Created
February 19, 2015 09:21
-
-
Save viralvadgama/79bc85b70e052c365a79 to your computer and use it in GitHub Desktop.
Check if there is any issue with server session settings for early expiration
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
ob_start(); | |
echo 'Session Cookie: '; | |
if( isset($_COOKIE[session_name()]) ) | |
{ | |
echo 'Present; Content: ' . $_COOKIE[session_name()] . '<br>'; | |
if( session_id() == '') | |
{ | |
echo 'Session not started; starting session<br>'; | |
session_start(); | |
if( strcasecmp(session_id(), $_COOKIE[session_name()]) == 0 ) echo 'Session ID matches cookie value.<br>'; | |
else echo 'Session ID: ' . session_id() . ' - Doesn\'t match cookie value<br>'; | |
if( isset($_SESSION['a2test']) ) | |
{ | |
$time_diff = intval($_SERVER['REQUEST_TIME']) - intval($_SESSION['a2test']); | |
echo 'a2test present in $_SESSION: ' . date('n/j/Y g:i:s a',$_SESSION['a2test']) . '<br>'; | |
echo 'Time since a2test set: ' . number_format(($time_diff/60.0),2) . ' minutes<br>'; | |
} | |
else | |
{ | |
echo 'New session, setting a2test value in $_SESSION to current time: ' . date('n/jY g:i:s a',$_SERVER['REQUEST_TIME']) . '<br>'; | |
echo 'Please check again in a few minutes.<br>'; | |
$_SESSION['a2test'] = $_SERVER['REQUEST_TIME']; | |
} | |
} | |
} | |
else echo 'Not present; may have been deleted or expired.'; | |
ob_end_flush(); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment