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
  1. #1
    New Coder
    Join Date
    Jul 2007
    Location
    UK
    Posts
    36
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Active user list

    Edited( i have now done the active user list, but problem)

    I have now created an active user list, when you login, it inserts the users username into a table called online_users, this is the code which also allows the user to login:
    PHP Code:
    <?php
    session_start
    ();

    $_SESSION['loggedin']=false;

    $username="******";
    $password="******";
    $database="******";

    mysql_connect('************',$username,$password);
    @
    mysql_select_db($database) or die("Unable to select database");

    $loginname $_POST['loginname']; $password $_POST['password'];

    $result MYSQL_QUERY("SELECT * from users WHERE loginname='$loginname'and password='$password'")
    or die (
    "Incorrect username or password");

    if (
    $row mysql_fetch_array($result)) 
    {
    $_SESSION['loginname'] = $row['loginname'] ; $_SESSION['email'] = $row['email'] ; $_SESSION['Loggedin'] = true 

    header("location:index.php");
    echo 
    'WELCOME '.$_SESSION['loginname'] ; 
    $_SESSION['incorrect_login'] = 'true'
    header("location:error_login.php");

    $query="INSERT INTO online_users
    (loginname) 
    VALUES
    ('$loginname')"
    ;   
    $result=mysql_query($query);}
    else 
    {
    $_SESSION['incorrect_login'] = 'true'

    header("location:index.php");}  

    ?>
    That bit works fine, the username is shown on the active user box.

    This is the code i have used to remove the username of the online users box which is the logout:
    PHP Code:
    <?php
    session_start
    ();
    $_SESSION['Loggedin'] = 'false';

    $username="******";
    $password="******";
    $database="******";

    mysql_connect('************',$username,$password);
    @
    mysql_select_db($database) or die("Unable to select database");

    mysql_query("DELETE FROM online_users WHERE $_SESSION['loginname']==loginname"
    or die(
    mysql_error());  

    header("location:index.php");
    ?>
    The problem is, is that it doesnt delete the username, so when you login again your username is shown twice, any ideas that will help thanks.

    This is the error i get:

    Parse error: parse error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in e:\domains\s\smgames.staticfire.co.uk\user\htdocs\logout.php on line 13
    Last edited by SMGames; 07-02-2007 at 12:47 PM. Reason: Changes made.
    http://www.smgames.staticfire.co.uk Under construction, Currently hiring mods and admins anyone interested pm me.

  • #2
    Regular Coder
    Join Date
    Mar 2004
    Location
    Australia
    Posts
    217
    Thanks
    0
    Thanked 1 Time in 1 Post
    Add an extra column to the user table for online status. value: 1 online, 0 offline? change value when they login?

  • #3
    New Coder
    Join Date
    Jul 2007
    Location
    UK
    Posts
    36
    Thanks
    0
    Thanked 0 Times in 0 Posts
    The comment above, was from before i edited the post.
    http://www.smgames.staticfire.co.uk Under construction, Currently hiring mods and admins anyone interested pm me.


  •  

    Posting Permissions

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