...

View Full Version : Active user list



SMGames
07-01-2007, 01:21 PM
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
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
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

Serex
07-01-2007, 05:31 PM
Add an extra column to the user table for online status. value: 1 online, 0 offline? change value when they login?

SMGames
07-01-2007, 06:52 PM
The comment above, was from before i edited the post.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum