PHP Login System with Admin Features

This forum was created to talk about the PHP Login System with admin features created by jpmaster77 on evolt's website


    Sessions

    Share
    avatar
    s.w.vanderlaan

    Number of posts : 19
    Age : 39
    Localisation : The Netherlands
    Registration date : 2009-03-22

    Sessions

    Post  s.w.vanderlaan on Wed Apr 15, 2009 4:58 am

    Hi,

    Here we go again. About sessions.

    How come:
    • the session is not terminated if I close the browser; the user is still displayed in other browsers as being logged in...?
    • when I do nothing for, say 5 minutes, the session is not terminated...?


    The code I use to show the logged in users:
    Code:
    <table align="right" cellpadding="2" cellspacing="0">
    <tr>
    <td>Logged in as:</td><td><font color=\"#99CC00\"><?php echo $session->username; ?></font></td>
    </tr>
    <tr>
    <td valign="top">
    Active users:
    </td>
    <td>
    <?php
    if(!defined('TBL_ACTIVE_USERS')) {
      die("Error processing page");
    }
    $q = "SELECT username, ip FROM ".TBL_ACTIVE_USERS." WHERE username != '$session->username' ORDER BY timestamp DESC,username";
    $result = $database->query($q);
    /* Error occurred, return given name by default */
    $num_rows = mysql_numrows($result);
    if(!$result || ($num_rows < 0)){
      echo "Error displaying info.";
    }
    else if ($num_rows > 0){
      /* Display active users */
      for($i=0; $i<$num_rows; $i++){
          $uname = mysql_result($result,$i,"username");
         echo "<font color=\"#FF9900\">$uname</font><br />";
         echo "";
      }
    }
    ?>
    </td>
    </tr>
    </table>

    And by the way: if there's only one user logged in, how can I arrange that "Active users:" is not displayed?

    Thanks.

    Sander
    avatar
    Linchpin311

    Number of posts : 220
    Age : 33
    Localisation : Long Island
    Registration date : 2007-05-14

    Re: Sessions

    Post  Linchpin311 on Wed Apr 15, 2009 6:58 am

    the session is not terminated because we never tell the session to terminate.

    i have been using this script in a lot of my projects for years and just figured this out not too long ago! i posted a solution here. i havent looked at it in some time so it may need to be revamped but the idea is all right there.

    s.w.vanderlaan wrote:And by the way: if there's only one user logged in, how can I arrange that "Active users:" is not displayed?
    you would have to edit the code to detect when there is only one user logged in (something like when there is only one row in the active users table) and not include the view active users part.


    _________________
    in the end, the universe tends to unfold as it should...

    Also note that it is your responsibility to die() if necessary.

      Current date/time is Tue Dec 11, 2018 6:10 am