Jump to content

finding out users on pages...


runnerjp

Recommended Posts

i have five forum pages

 

http://www.site.com/members/index.php?page=forum&forum=general

http://www.site.com/members/index.php?page=forum&forum=races

http://www.site.com/members/index.php?page=forum&forum=training

http://www.site.com/members/index.php?page=forum&forum=qa

http://www.site.com/members/index.php?page=forum&forum=injuries

 

i currently use this code to find out if a user is on a page

 

<? $result = mysql_query("SELECT * FROM useronline WHERE(file='http://www.site.com/members/index.php?page=forum&forum=$forum')");
while($row = mysql_fetch_array( $result )) {

$last_active = time() - $row['timestamp'];
$onlineuser = $row['user'];
}

if($last_active < 300) {
echo $onlineuser;
}
?>

 

is there away i can make it so it find everyone one them links...

Link to comment
https://forums.phpfreaks.com/topic/127555-finding-out-users-on-pages/
Share on other sites

ok on all my pages i record what user is viewing them... the time they viewed them and so on like this

 

<?php $timestamp = time(); 
$timeout = $timestamp - 180; 
$username = get_username($_SESSION['user_id']); 
function selfURL() 
{ 
    $s = empty($_SERVER["HTTPS"]) ? '' : ($_SERVER["HTTPS"] == "on") ? "s" : ""; 
    $protocol = strleft(strtolower($_SERVER["SERVER_PROTOCOL"]), "/") . $s; 
    $port = ($_SERVER["SERVER_PORT"] == "80") ? "" : (":" . $_SERVER["SERVER_PORT"]); 
    return $protocol . "://" . $_SERVER['SERVER_NAME'] . $port . $_SERVER['REQUEST_URI']; 
} 
function strleft($s1, $s2) 
{ 
    return substr($s1, 0, strpos($s1, $s2)); 
} 
$filename = (selfURL()); 
//Insert User 
$insert = mysql_query("REPLACE INTO `useronline` SET `timestamp`='$timestamp', `ip`='" . 
    $_SERVER['REMOTE_ADDR'] . "', `file`='$filename',`user`='$username',`user_id`='" . 
    $_SESSION['user_id'] . "'") or die(mysql_error()); 

?> 

 

so what i want to do is from file where the page is stored of the users currently viewed page on the site is pull how many users are on all the pages i mentioned above...

 

example  admin,runnerjp and skunkbad are on the forum

most sites that track users and display who is online show who is online every 5 minutes or so, so you could do the same if you search your database for users who have timestamps that are within a range of the current time to the current time minus 5 minutes.

 

Your query would be something like:

 

"select * from userLog where lastPageLoad >= ($currentTime - 300)"

 

THIS IS OBVIOUSLY NOT  A REAL SQL STATEMENT, but with some work on your part, you could make an sql statement that does work, and displays who is online semi-accurately.

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.