Jump to content

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.

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.