0

I try atmost but I failed to destroy session within in 1 minute. I am using PHP destroy code which is given below but it is not working.

<?php 
    session_start();
    $_SESSION['start'] = "start session";
    if(isset($_POST['destroy'])){
        session_cache_expire(1);
    } 
?>    
jmattheis
  • 10,494
  • 11
  • 46
  • 58
  • Follow this link - https://stackoverflow.com/questions/17179249/session-destroy-after-certain-amount-of-time-in-php – Dharmendra Singh Jul 08 '17 at 05:24
  • [How do I expire a PHP session after 30 minutes?](https://stackoverflow.com/q/520237/6521116) – LF00 Jul 08 '17 at 05:28
  • 3
    Possible duplicate of [session\_destroy() after certain amount of time in PHP](https://stackoverflow.com/questions/17179249/session-destroy-after-certain-amount-of-time-in-php) – James Douglas Jul 08 '17 at 10:09

2 Answers2

0
session_start();

// 1 mins in seconds
$inactive = 60; 

$session_life = time() - $_session['timeout'];

if($session_life > $inactive)
{  session_destroy(); header("Location: logoutpage.php");     }

S_session['timeout']=time();

refer this link

or you can use

ini_set('session.gc_maxlifetime',1);
Neeraj Rathod
  • 1,609
  • 4
  • 18
  • 25
0
        <?php
        define("DURATION",'1'); // define duration constant in minutes
        session_start();
        $duration = (DURATION * 60); // duration in seconds

        if(isset($_SESSION['started'])) //check whether session is set or not
        {
            $time = ($duration - (time() - $_SESSION['started']));
            if($time <= 0)
            {
                session_destroy();
                echo "Session has been expired. You were logged in for one minute";
            }
        } 
       else
        {
            $_SESSION['started'] = time();
        }
        ?>
swati
  • 11
  • 3