WebSite X5Help Center

 
Duncan Baker
Duncan Baker
User

Session code  en

Auteur : Duncan Baker
Visité 1049, Followers 1, Partagé 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

  1. session_start();
  2. // set timeout period in seconds
  3. $inactive =600;
  4. // check to see if $_SESSION['timeout'] is set
  5. if(isset($_SESSION['timeout'])){
  6. $session_life = time()- $_SESSION['timeout'];
  7. if($session_life > $inactive)
  8. { session_destroy(); header("Location: logoutpage.php");}
  9. }
  10. $_SESSION['timeout']= time();
Posté le
2 RéPONSES - 1 CORRECT
Paul M.
Paul M.
Moderator

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

Lire plus
Posté le de Paul M.
Duncan Baker
Duncan Baker
User
Auteur

Thanks Paul

Lire plus
Posté le de Duncan Baker