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
Share on other sites

thats kinda what im looking for, but with commas but it doesnt end with one like
ki, user, user2,

but i want it like how it shows the users viewing the current page like, Users Viewing Forum: ki, user, user2
Link to comment
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.