Forgot Password / Register
Site Statistics
Total Members: 520
Total Tutorials: 242
Newsest User: 8884244477
Todays Unique Hits: 411
1 Users 10 Guests Online

Whos Online

People are wanting whos online scripts so here's a simple one.

This idea came from Diablosblizz.

Run this in phpmyAdmin
Code

ALTER TABLE `members` ADD `online` INT( 1 ) NOT NULL DEFAULT '0';


In login.php find..
Code

$_SESSION['id'] = "$user[id]";
$_SESSION['password'] = "$user[password]";


And after put..
Code

$online = mysql_query("INSERT INTO `members` (`username`, `online`) VALUES('$username','1')");


This makes the user online as such. making the value 1 when they login and 0 when they logout.
So that makes the user online. but what if they wanted to logout?
In logout.php find..
Code

if(isset($_GET['logout'])){


And after put..
Code

$offline = mysql_query("INSERT INTO `members` (`username`, `online`) VALUES('$username','0')");


this shows them as offline
Want to view whos online. Nah didn't think so but here it is anyways.
Code

<?php
include ("config.php");
$sql = mysql_query("SELECT * from members where online == '1'");
while ($online = mysql_fetch_array($sql))
{
$username = $online[username];
echo ("- $username<br>");
//displays the online users
}
?>


this grabs all the users that have the value 1 which means they are online and displays it

be sure to look out for more tuts by be.
SkillMaster
Views:
2915
Rating:
Posted on Saturday 15th November 2008 at 09:57 PM
shedh
shedh
this is right

<?php
session_start();
include"config.php";

$users = mysql_query("SELECT * FROM `members` WHERE `online`='1'");

while($online = mysql_fetch_array($users))
{
echo $online['username'] . " " . $online['ID'];
echo "<br />";
}
?>

A quick trip to W3SCHOOLS don't hurt anyone
Posted on Thursday 31st July 2008 at 03:46 PM
ShadowMage
ShadowMage
SQL query is wrong.
Posted on Thursday 31st July 2008 at 12:51 PM
jambomb
jambomb
I get this error:

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/*****/public_html/HighRize/main/whosonline.php on line 126
Posted on Tuesday 3rd June 2008 at 09:54 PM
DanielXP
DanielXP
Why is this code doing a insert instead of an update to set if the user is online or not?
Posted on Tuesday 3rd June 2008 at 08:16 PM
Chikenty
Chikenty
Alright well this is the 2nd tutorial where it has not worked simply because people just aren't testing it or are ripping it. I blow at coding and could see a problem from the start. Tutorial tells you to Insert into 'members' which simply only re-adds the name thats logged in with.
Im not sure how the bbcode on this comment system goes so i can only type the stuff out so here this goes in the login.php as stated in the tutorial:
$online = mysql_query("UPDATE `members` SET`online` = '1' WHERE `username` = '$username'");

This goes in the logout.php as shown above:
$offline = mysql_query("UPDATE `members` SET `online` = '0' WHERE `username` = '$logged[username]'");

And this is just a small add-on to where is shows whos online i linked it to the profile.
<?php

include("config.php");

$sql = mysql_query("SELECT * from members where online = '1'");

while ($online = mysql_fetch_array($sql))

{

$username = $online[username];

echo ("<a href='members.php?user=$username'>$username</a> ");

//displays the online users

}

?>
Posted on Tuesday 29th May 2007 at 01:29 AM
MCP
MCP
Well see that is the problem. There are bits of code to edit into each login and logout. So the only thing is you need to know is I followed this tutorial to a T.

Still only a blank page.
Posted on Tuesday 29th May 2007 at 01:18 AM
James
James
post you code so we can take a look
Posted on Monday 28th May 2007 at 10:34 PM
MCP
MCP
Sorry bout the double post, but please help me in a PM.
Thanks
Posted on Monday 28th May 2007 at 03:13 PM
MCP
MCP
All I see is a blank page when this is properly installed.

Help?
Posted on Monday 14th May 2007 at 11:11 PM
Diablosblizz
Diablosblizz
Nah, my idea doesn't even work after what you posted in forums....