Login Timeout

Collapse
This topic is closed.
X
X
 
  • Filter
  • Time
  • Show
Clear All
new posts
  • glutenf1
    Private First Class

    • Feb 2013
    • 6

    Login Timeout

    Hey, I have a login form on my site. I've noticed that it stays logged in indefinitely. Is there a way I can get it to timeout after a certain length of inactivity? Thanks (www.glutenfreemealplanner.com)
    Gluten-Free Meal Planner
  • Vasili
    Moderator

    • Mar 2006
    • 14683

    #2
    Re: Login Timeout

    Originally posted by glutenf1 View Post
    Hey, I have a login form on my site. I've noticed that it stays logged in indefinitely. Is there a way I can get it to timeout after a certain length of inactivity? Thanks www.glutenfreeplanner.com
    If you are using the BlueVoda Login Script, in the instructions where you create the Object on the protected page, these are the methods you will use if using BlueVoda version 12 and later:

    Insert the "Protect Page" object in the pages that you need to protect.

    Right click it and select "Convert to Form". The object will be converted to a HTML box. Double click it and you will see its code that will be looking like this:

    <?php
    session_start();
    if (!isset($_SESSION['username']))
    {
    header('Location: error.php');
    exit;
    }
    ?>


    Insert the following code just AFTER the line session_start();

    if(!isset($_SESSION['logintime'])){
    $_SESSION['logintime'] = time();
    }else {
    if(time() > $_SESSION['logintime'] + 15 * 60){
    unset($_SESSION['username']);
    }else{
    $_SESSION['logintime'] = time();
    }
    }

    15 is the session expiry in minutes. You can change it to whatever you need.

    Please note that as is, the code, will renew the session expiry for 15 minutes after each page load. So if the user keeps on moving on the site, his session is renewed. Otherwise it expires after 15 minutes.

    THE ABOVE IS ONLY AVAILABLE USING BV12


    If you have BV 11 this is not available.
    I
    f you want to continue working with BV 11, then:

    Add a small HTML box in your page. Paste the entire code, that is

    <?php
    session_start();
    if(!isset($_SESSION['logintime'])){
    $_SESSION['logintime'] = time();
    }else {
    if(time() > $_SESSION['logintime'] + 15 * 60){
    unset($_SESSION['username']);
    }else{
    $_SESSION['logintime'] = time();
    }
    }
    if (!isset($_SESSION['username']))
    {
    header('Location: error.php');
    exit;
    }
    ?>

    Remove the standard Protect Page object.
    The "time()" should remain as is (this is not where you insert a time parameter).

    Using a HTML box, you will have to manually type the "Access denied Page" (which I supposed to be the "error.php" page but you can have any page you like.)

    If you want to restrict access to specific users, you should further modify the code.
    . VodaWebs....Luxury Group
    * Success Is Potential Realized *

    Comment

    • glutenf1
      Private First Class

      • Feb 2013
      • 6

      #3
      Re: Login Timeout

      Thanks for the code. I applied it and it seems to work for timing out, but I'm having a little bit of trouble logging back in. If I try to log back in after it has timed out, I cannot get in with the same password and username. Any suggestions on how to fix this? Here is the actual code that I am using ...

      <?php
      session_start();
      if(!isset($_SESSION['logintime'])){
      $_SESSION['logintime'] = time();
      }else {
      if(time() > $_SESSION['logintime'] + 15 * 60){
      unset($_SESSION['username']);
      }else{
      $_SESSION['logintime'] = time();
      }
      }
      if (!isset($_SESSION['username']))
      {
      header('Location: ./mealplans.php');
      exit;
      }
      ?>
      Gluten-Free Meal Planner

      Comment

      • Vasili
        Moderator

        • Mar 2006
        • 14683

        #4
        Re: Login Timeout

        Sorry - not a Coder!

        It took me a good hour just to find this proper Code buried in the Forums to present to you as your 'Solution' .....
        . VodaWebs....Luxury Group
        * Success Is Potential Realized *

        Comment

        Working...
        X