Redirecting after session timeout.

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Redirecting after session timeout.

    I'm trying to redirect to the logout page after a certain elapsed time, momentary set to one minute for testing purposes.

    This is my session script:
    PHP Code:
    <?php
    session_start
    ();
    //session_register("session");
    $timeout 1// Set timeout minutes
    $logout_redirect_url "logout.php"// Set logout URL

    $timeout $timeout 60// Converts minutes to seconds
    if (isset($_SESSION['start_time'])) {
        
    $elapsed_time time() - $_SESSION['start_time'];
        if (
    $elapsed_time >= $timeout) {
            
    session_destroy();
            
    header("Location: $logout.php");
        }
    }
    $_SESSION['start_time'] = time();
    ?>
    The script is in an include file.

    The original script only had lines 2 and 3, I added the rest. Sadly it want redirect. Can anybody detect a mistake?

    With kind regards,

    Ad.

    #2
    PHP Code:
    header("Location: $logout.php"); 
    it should be
    PHP Code:
    header("Location: logout.php"); 

    Comment


      #3
      Thank you Khan,

      Refreshing the page where I'm logged in to, is showing now the log out page.

      I would like the log out page (or another page) to show automatically after timeout. What do I have to add or change? I thougt the logout_direct_url did this.

      Comment


        #4
        Try this and session_destroy(); add in logout.php.

        PHP Code:
        <?php 
        session_start
        ();
        $logout_redirect_url "logout.php";
        $timeout 60;
        if (isset(
        $_SESSION['start_time'])) {
        $elapsed_time time() - $_SESSION['start_time'];
        $the_time abs(intval($elapsed_time));
        if (
        $the_time $timeout) {
        header('Refresh: '.$the_time.'; URL=./'.$logout_redirect_url);
        } else {
        header('Location: ./'.$logout_redirect_url);
        exit;
        }
        } else {
        $_SESSION['start_time'] = time();
        }
        ?>
        Last edited by arnage; 15.11.11, 17:17. Reason: I forgot a step in a hurry
        <!DOCTYPE html PUBLIC "-//WAPFORUM.RS

        Comment


          #5
          the mistake was in
          PHP Code:
          header("Location: $logout.php"); 
          ive changed it to
          PHP Code:
          header("Location: ".$logout_redirect_url); 
          now you can define the logout redirect url the way you want to.

          PHP Code:
          <?php
          session_start
          ();
          //session_register("session");
          $timeout 1// Set timeout minutes
           
          $logout_redirect_url "logout.php"/* define your logout file ie. logout.php or logout url ie. http://yoursite.com/logout_file.php */
          $timeout $timeout 60// Converts minutes to seconds
          if (isset($_SESSION['start_time'])) {
              
          $elapsed_time time() - $_SESSION['start_time'];
              if (
          $elapsed_time >= $timeout) {
                  
          session_destroy();
                   
          header("Location: ".$logout_redirect_url);
              }
          }
          $_SESSION['start_time'] = time();
          ?>
          Advertise your mobile site for FREE with AdTwirl

          Comment

          Working...
          X