Jump to content

users online


ki

Recommended Posts

when I got helped, It only showed that some users were online... but then I modified it so it showed each one...


here is the script
make sure your users table has a column named online...

ALTER TABLE `tablename` ADD online TIMESTAMP;


Have this in another page called showusers.php

[code]
<?php
session_start();
//Connect to the database
if (isset($_SESSION['username'])) { // checking to see if there is a user logged in
// user logged in so update current time in 'online' column of 'user' table
$query = "UPDATE users SET online = now() WHERE username = \"".$_SESSION['username']."\"";
$result = mysql_query($query);
}
$query = "SELECT username,online FROM users WHERE now() - online<=500";
$result = mysql_query($query);
echo "Users online: ";
while ($row = mysql_fetch_assoc($result)){
if($row['diff'] < 500) {
// user has been online within the last 5 minutes
echo $row['username'] . " ";
}
}
?>
[/code]

After you modify the script to work the way you need... put this on pages that you want to show who is online:

include "showusers.php";

if you have any questions, just reply or send me a PM
Link to comment
https://forums.phpfreaks.com/topic/31438-users-online/#findComment-145628
Share on other sites

Here... If you make another column called current_page... make it a varchar(50)...

then on all of the pages include a script that updates the current_page to $_SERVER['PHP_SELF']... after it 'SETS' that value, then select all of the users that have the current_page to = $_SERVER['PHP_SELF']... and if it equals echo their username...

if that isnt hint enough, I dont know what is.
Link to comment
https://forums.phpfreaks.com/topic/31438-users-online/#findComment-146131
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.