Session code
Author: Duncan Baker
Visited 1047,
Followers 1,
Shared 0
I know that you cannot help me on the actual code but I would like to insert code for session time out (see below) so that the page times out after 10 mins of no sue.
Where should I put the code? Before closing the head tag or somewhere else?
Many thanks,
Duncan
- session_start();
- // set timeout period in seconds
- $inactive =600;
- // check to see if $_SESSION['timeout'] is set
- if(isset($_SESSION['timeout'])){
- $session_life = time()- $_SESSION['timeout'];
- if($session_life > $inactive)
- { session_destroy(); header("Location: logoutpage.php");}
- }
- $_SESSION['timeout']= time();
Posted on the
Hello Duncan,
Code like this has to go in the header as opposed to the body, as errors will be invoked if you call the header function after any output has been sent to the browser... i.e. this line:
header("Location: logoutpage.php");
So insert it in one of the following places:
Before closing the HTML tag;
After opening the HEAD tag;
Before closing the HEAD tag;
Remember to wrap the code in PHP tags...
<?php
?>
And, of course, you will also need to create the 'logoutpage.php' in your WebSite X5 project.
Kind regards,
Paul
Author
Thanks Paul