How to set session for specific time

Set PHP session timeout or session expire automatically process after 10 minute using easy PHP code. PHP session will timeout default once given time interval over.

PHP simple code to set session for specific time. Suppose in application need to allow user action for specific time, i.e., Enter some code or detail and if user not follow procesure in time, application not allow to continue user action. Example is given in 2 simple steps.

Here example given with 10 min session expiration time.

PHP session timeout code example

1) Set session variable with future time:

<?php $_SESSION['expire'] = time() + (60 * 10); ?>

2) Check session variable is not expired:

    && $_SESSION['expire'] > time()){
        //do stuff
        //destroy session or logout etc...