Page 1 of 1
Using PHP to read SITEMETER's "Who's online" - Pos
Posted: Sat Jan 01, 2005 9:27 pm
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.
Posted: Sat Jan 01, 2005 9:37 pm
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.

Posted: Sat Jan 01, 2005 9:38 pm
by camarosource
Is this typically a hard script to write?
Posted: Sat Jan 01, 2005 11:17 pm
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.

Posted: Mon Jan 03, 2005 4:06 am
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!

Posted: Mon Jan 03, 2005 4:34 am
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.