Close a session in php after 10 minutes

Posted on 2014-08-29
Last Modified: 2014-08-29
I have a system created in PHP with MSSQL, this system is public and anyone from around the world can see it, one of the things I need is to create a session to control some part of the system but now my problem is that sessions are giving me problems because the user could let the browser open and the session is still valid and the server at some point is hanging because is consuming many resources.

Is there any way to close the session after x period of time? I have been trying with the settings in the php.ini file but that not solve my problem, some other way to force this?

Thanks in advance for the help.
Question by:GeorgeTowers
    LVL 28

    Accepted Solution

    I had a similar situation before, all I did was restart the session on each page keeping the session variables and then set a session timeout.


            $_SESSION['expire'] = $_SESSION['start'] + (1 *600);

    So php takes the session start value and adds 600 seconds for a 10 minute timeout.

    Author Closing Comment

    Thanks. I will do that.

    Featured Post

    How your wiki can always stay up-to-date

    Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
    - Increase transparency
    - Onboard new hires faster
    - Access from mobile/offline

    Join & Write a Comment

    Article by: Nadia
    Suppose you use Uber application as a rider and you request a ride to go from one place to another. Your driver just arrived at the parking lot of your place. The only thing you know about the ride is the license plate number. How do you find your U…
    Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
    Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
    The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

    746 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    14 Experts available now in Live!

    Get 1:1 Help Now