How to close a session after 10 minutes of inactivity.

I need so help in creating some mechanized way of closing or destroying a session after 10 minute of inactivity.

The application is similar to login into your bank account, a user logs in using username and password and is able to bring up several pages of there owned information.

What I need is to destroy the session 10 minutes after he has clicked for the last time.

Code sample will be greatly appreciated.


Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

You can do this

ini_set("session.gc_maxlifetime", 600); // 600 secs, 10 min


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Or you can also set this in the PHP.ini

; After this number of seconds, stored data will be seen as 'garbage' and
; cleaned up by the garbage collection process.
session.gc_maxlifetime = 600

rcleonAuthor Commented:
Thanks you so much for your help,

In both of these cases, would it close after 10 min regardless of activity?

I need closing after 10 min of Inactivity.

Or is there a way to alert then than the session is going to close and extend there time.


Cloud Class® Course: Microsoft Windows 7 Basic

This introductory course to Windows 7 environment will teach you about working with the Windows operating system. You will learn about basic functions including start menu; the desktop; managing files, folders, and libraries.

yes this is with inactivity.

And yes, you can alert the user. You would basically setup a javascript that would run while the user is inactive, and after 540 seconds say, pop up a reminder letting them know. Make the javascript run only when there is no activity. and stop/reset when there is.

Here is a little snip that would probably work.

function isInactive(){
  var msg= "Notice of Inactivity and allow confirm of redirection...";
  var temp= (window.confirm(msg)) ? '' : null;
  if (temp) window.location.href= temp;
var t= window.setTimeout("isInactive()", 5000);

rcleonAuthor Commented:
Thank you soooooooooooooo much it works great.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.