I have a webpage. The authentication to the webpage is handled by a ldap server I have set up. Now I wan`t to implement sessions, so that when a user is inactive for a period of time (in the case below, 10 seconds), the session will end and the user will unbind from the ldap server. I found this excerpt of code:
<?php
session_cache_expire(20);
session_start();
$inactive = 10;
if(isset($_SESSION['start'])) {
$session_life = time() - $_SESSION['start'];
if($session_life > $inactive){
header("Location: endSession.php");
}
}
$_SESSION['start'] = time();
?>
It is not working. If I refresh the page it redirects me to my ‘endSession.php’ page, even if I`m active.
Just call the above function at the top of every protected page. This will handle all the authentication processes. It will return the LDAP connection resource if the user is authenticated, and redirect them to
endSession.phpif they are not.Just place this line at the top of each page:
…and the function will do all the legwork for you.