Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3

Thread: SESSION Help

  1. #1
    Regular Coder
    Join Date
    Jul 2007
    Posts
    571
    Thanks
    25
    Thanked 28 Times in 28 Posts

    SESSION Help

    The code below shows a session that is created when people log into my site. The problem I am having is that after 30mins on the site they get booted off. What I want is for them to get booted off only if they are idle for 30mins. Anyone know why my code is not archiving this?

    From Login.php
    PHP Code:
    // Set the session data & redirect.
    session_name ('YourVisitID');
    session_set_cookie_params(1800);
    session_start();
    $_SESSION['user_id'] = $row[0];
    $_SESSION['username'] = $row[1];
    $_SESSION['agent'] = md5($_SERVER['HTTP_USER_AGENT']);
    header("location:$headerURL");
    exit(); 
    // Quit the script. 
    at the top of every member page:
    PHP Code:
    session_name ('YourVisitID');
    session_set_cookie_params(1800);
    session_start(); // Start the session.

    // If no session value is present, redirect the user.
    if (!isset($_SESSION['agent']) OR ($_SESSION['agent'] != md5($_SERVER['HTTP_USER_AGENT'])) ) {
        
    header("Location: $SiteURL");
        exit(); 
    // Quit the script.


  • #2
    Regular Coder mlse's Avatar
    Join Date
    Mar 2005
    Posts
    624
    Thanks
    20
    Thanked 19 Times in 18 Posts
    Hi there,

    The PHP manual for session_start says "session_start() creates a session or resumes the current one". Perhaps, therefore, the code at the top of each page is merely resuming the time-limited session that was created in Login.php and your call to session_set_cookie_params is merely adjusting the time on the already started session (if you see what I mean!).

    Or perhaps I'm wrong! I've never used time-limited session cookies to control short-timespan sessions like that -- I tend to use some kind of timer class of my own.

  • #3
    Regular Coder Iszak's Avatar
    Join Date
    Jun 2007
    Location
    Perth, Western Australia
    Posts
    332
    Thanks
    2
    Thanked 58 Times in 57 Posts
    I suggest adding a session variable like this and checking if it's past.

    SET SESSION VARIABLE
    PHP Code:
    $_SESSION['timeout'] = time()+30*60
    CHECK IF TIMEOUTED
    PHP Code:
    if (time() > $_SESSION['timeout'])
    {
      
    // SESSION TIMED OUT

    Rrenew the variable if they go to a new page.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •