Jump to content
Larry Ullman's Book Forums

Recommended Posts

Hi ,this book are really good , simple and easy to understand , don't have any problem on understanding your words so far. I have apply to two of my project .

 

This is not really a problem , just not sure where to start off .

 

I was trying to improve the login system , because when the user forget to click the logout button , the session doesn't logout automatically.What i trying to do is make a session expire after 15 minutes of inactivity ? Any ideas ?

 

[sOLVED]

used this solution

 

apply to include/config.inc.php

just after the session_start()

Hope this can helps

 



$live = false;

// Errors are emailed here:
$contact_email = 'abc@gmail.com';

define ('BASE_URI','.');
define ('BASE_URL','www.domain.com/');
define ('MYSQL', BASE_URI . '/include/mysql.inc.php');

// Start the session:
session_start();
$timeout = 15; // Set timeout minutes
$logout_redirect_url = "index.php"; // Set logout URL

$timeout = $timeout * 60; // Converts minutes to seconds
if (isset($_SESSION['start_time'])) {
   $elapsed_time = time() - $_SESSION['start_time'];
   if ($elapsed_time >= $timeout) {
       $_SESSION = array(); // Destroy the variables.
       session_destroy();
       setcookie (session_name(), '', time()-86400, '/'); // Destroy the cookie.
       header("Location: $logout_redirect_url");
   }
}
$_SESSION['start_time'] = time();

Share this post


Link to post
Share on other sites

I did read about this in stackoverflow...still you want to suggest this bad solution since its not reliable?

Updated my homework. What if i wan to use this code?meet the logic? where should i put to get it work?

Share this post


Link to post
Share on other sites

The following code has been working for me. I have placed this in the config file.

 

//create a session
if (!isset($_SESSION)) {
session_start();
}
//store the current time
$now = time();
// get the time the session should have expired
$limit = $now - 60 * 30;
// check the time of the last activity
if (isset ($_SESSION['last_activity']) &&
$_SESSION['last_activity'] < $limit) {
// if too old, clear the session array and redirect
 $_SESSION = array();
 header('Location: http://xxxxxxxxxxxx/expired.php');
 exit;
}else {
 //otherwise, set the value to the current time
$_SESSION['last_activity'] = $now;
}

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
Sign in to follow this  

×
×
  • Create New...