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.