Using PHP to read SITEMETER's "Who's online" - Pos

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
camarosource
Forum Commoner
Posts: 77
Joined: Sat Aug 03, 2002 10:43 pm

Using PHP to read SITEMETER's "Who's online" - Pos

Post by camarosource »

I use http://www.sitemeter.com SiteMeter website meter for years now and had an idea which apparently David Smith (Sitemeter's Inventor) says IS in fact possible. However I really have no idea how this would be done and so I was hoping someone here could help?

I would like to find out how to write a PHP script that would be able to read Sitemeter's "who's online" amount and display it on my website.

For example: Let's say if I went into sitemeter (http://www.sitemeter.com/default.asp?ac ... &report=15) and it showed 24 people online. I would like the PHP script to see there is 24 listed and display "24" on the website.

Thanks.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

I typically use [php_man]curl[/php_man] or [php_man]file_get_contents()[/php_man] depending on what information and controls are needed. After the content is downloaded, I use [php_man]preg_match()[/php_man] or its siblings to extract the information I need. Remember to get SiteMeter's permission to extract page information and display it on your site. ;)
camarosource
Forum Commoner
Posts: 77
Joined: Sat Aug 03, 2002 10:43 pm

Post by camarosource »

Is this typically a hard script to write?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

only the regular expressions needed to extract the information can be challenging. However, it can be done without regular expressions, it just takes a bit more code. :)
camarosource
Forum Commoner
Posts: 77
Joined: Sat Aug 03, 2002 10:43 pm

Post by camarosource »

I posted the question on a msgboard and someone told me about SNOOPY and wrote a small script that would read http://www.sitemeter.com 's who's online list and dislplay the number of people using your SNOOPY.


This is the small files he wrote:

[WHOISONLINE.PHP]

Code: Select all

<?php
<?php
include ("snoopy.class.php");
$url = "http://www.sitemeter.com/default.asp?action=stats&site=sm4camarosource&report=15";
$online_count = 0;
// Create a new instance of the Snoopy Class.
$snoopy = new Snoopy;
  // Fetch all the links from the desired website.
   $snoopy->fetchlinks($url); // Fetch all the links from the given URI.
  // Now we will sift through all the links to find just the one we need.
  $haystack = $snoopy->results; // This is an array containing all the links from fetchlinks.
  reset($haystack); 
  while (list($key, $val) = each($haystack)) 
  { 
 if (stristr($val,"&visit="))
 {
   $online_count++;
 } 
  } 
//display info
echo "Users online : $online_count";
?>
?>
I placed it (and ALL the snoopy files) into the http://camarosource.ca/php/snoopy/

http://camarosource.ca/php/snoopy/whoisonine.php

But when you run it, it says "Users online : 0"

Obviously it is not reading the who's online list. I am guessing it is perhaps because you have to log INTO sitemeter? If this is the case, how would I make it so it logs in? In order to log into your Sitemeter account to see your site's stats, you have to enter your username and password.

Please help.

Thanks a LOT! :-)
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

from a quick look at sitememter, it looks like they use a cookie to see if you are logged in. So, if you copy your cookie for sitemeter and have it sent through the request, you should be able to get it. I'm unsure snoopy is able to do such a thing, but I know [php_man]curl[/php_man] can.
Post Reply