Jump to content

How to use Sessions in and give session timeouts say after 5 minute user relogin


rakeshgr

Recommended Posts

Hello Everyone,

 

I am building a website using the PHP 5 and MySQL .I have set up all the required database ready and the PHP pages are linked with the database.I am able to traverse through my pages by querying through the database and inserting and retrieving the stored data from MySQL database.

 

Now i am trying to use sessions in my website so that i can limit the users access and implement session timeouts say if the user is not using the web page for 5 minutes then the session  is timed out and he is again asked to relogin.

 

I am trying to implement this functionality in my website.

 

Can anybody please help me in this regard.Please let me know how to secure my website by using session without cookies and what variables or function need to be used or is their any class which can be included in all my web pages so that it will be used to achieve the session timeouts for the specified time.

 

Can anybody please send me source code or example script or developed project where sessions are used and session timeouts arre given in order to logout the idle users afetr the specified time which is specified by us at the server side.

 

Thanks in advance and hope to get the feedback at the earliest.

 

thanks and regards,

rakesh.

Link to comment
Share on other sites

You could set a session to record the time they logged in and then check that against the current time when they go to the next page.

 

//set the login time in a session
$_SESSION['time_logged_in'] = time();


//check their time has not expired

$time_limit = 5 * 60; // 5 minutes
$time_limit = $_SESSION['time_logged_in'] + $time_limit;
$time_now = time();

if($time_limit > time_now)
  {
   echo 'Your session has expired';
  }

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

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.   Restore formatting

  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.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.