Solved

counting users on pages.

Posted on 2008-10-24
10
276 Views
Last Modified: 2012-05-05
throughout my site i track users...
i have a forum section and want to display how many users and who is viewing the forum...

the thing is i store the page next to the username that they are on and im woundering if i could search for short hand of the url... examples will help make this clearer...

here are a few examples of links on my forum

index.php?page=post&forum=<?php echo $forum?>
index.php?page=mainforums
index.php?page=reply&id=<? echo $id ?>

and so on... as you guys can see there are alot of veriations... is there away to search for the links that contain

index.php?page=reply
index.php?page=mainforums
index.php?page=post

to just display them??
0
Comment
Question by:runnerjp
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 4
10 Comments
 
LVL 39

Expert Comment

by:Roger Baklund
ID: 22796886
Where is the data stored? In a database? In a text file? Need more info...
0
 

Author Comment

by:runnerjp
ID: 22796928
sorry ok its stored in a database... below is how i store the information..
$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()); 
?>

Open in new window

0
 
LVL 39

Expert Comment

by:Roger Baklund
ID: 22797174
To select records from a database you would use the SQL SELECT statement. Something like this:

SELECT user, FROM useronline WHERE file LIKE "%index.php?page=reply%";

The LIKE operator allows a wildcard type search, % means any sequence of any characters.

To find currently online users (last ten minutes) within a particular page, the PHP would be something like the below:
$page = "index.php?page=mainforums";
$sql = "SELECT * FROM useronline 
  WHERE file LIKE '%$page%' AND
  timestamp > now() - interval 10 minute";
$res = mysql_query($sql) or die('Error: '.mysql_error());
if(mysql_num_rows($res) > 0) {
  echo '<div class="CurrentlyOnline">';
  while($row = mysql_fetch_assoc($res))
    echo $row['user'].'<br />';
  echo '</div>';
}

Open in new window

0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 39

Expert Comment

by:Roger Baklund
ID: 22797227
A should hurry to add that the database server can not use an index when you start the search phrase with %. It would be better for performance if you could do like this:


   WHERE file LIKE 'http://mydomain.com/path/$page%'

Open in new window

0
 

Author Comment

by:runnerjp
ID: 22797616
well i display my pages like so... http://mysite.com/members/index.php?page=reply
0
 
LVL 39

Expert Comment

by:Roger Baklund
ID: 22798109
Yes... if $page contains "index.php?page=reply" you would use this:


  WHERE file LIKE 'http://mysite.com/members/$page%'

Open in new window

0
 
LVL 39

Expert Comment

by:Roger Baklund
ID: 22798130
If I am not answering your question, I may have misunderstood. Please elaborate.
0
 

Author Comment

by:runnerjp
ID: 22798438
your kinda getting there lol

thing is its an include link so i have many files with index... im just looking for those with

index.php?page=reply
index.php?page=mainforums
index.php?page=post
0
 
LVL 39

Accepted Solution

by:
Roger Baklund earned 500 total points
ID: 22798518
The code I gave you answers how to get the users of one of those three pages, right? Are you looking for a way to get all three at the same time? It would be somthing like this:
WHERE 
  file LIKE 'http://mysite.com/members/index.php?page=reply%' OR
  file LIKE 'http://mysite.com/members/index.php?page=mainforums%' OR
  file LIKE 'http://mysite.com/members/index.php?page=post%'

Open in new window

0
 

Author Closing Comment

by:runnerjp
ID: 31509675
thats 100% what i was looking for.. i will start work on it right away ty
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
PHP Underscores vs. Directory separators 5 45
Delete image(s) associated with record(s) 16 45
PHP substring 3 49
Help installing Laravel app on MAMP on MAC 7 54
Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this. Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it i…
Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

737 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question