Today, while browsing my stats (provided via statcounter), I realized something interesting - I have no idea know who/what access my RSS feed.
So, I decided to see if I can write a simple script to write to a log file every time RSS is accessed.
Step 1: Script to write to a log file
$my_addy = $HTTP_SERVER_VARS['REMOTE_ADDR'];
$my_uri = $HTTP_SERVER_VARS['REQUEST_URI'];
$my_browser = $HTTP_SERVER_VARS['HTTP_USER_AGENT'];
$my_ref = $HTTP_SERVER_VARS['HTTP_REFERER'];
$my_date = date(’Ymd’);
$my_filename = “/your server/stats/rss.log”;
$my_time = date(’h:i:s’);
$log_data_line = “#$my_ref|$my_date|$my_browser|$my_addy|$my_time|\n\n”;
$fp = fopen($my_filename, “a”);
For the code to work:
- Paste it in a file with extension php, and upload that file to the base folder of your web site.
- You will need to change the first [ to an < and the last ] to an >
- Create a log file and replace /your server/stats/rss.log. Chmod that log file 666 (writeable)
Now, if you call this new script from the browser, it will dutyfully write a line to your new log file.
Step 2: Calling this process everytime someone requests your RSS/ATOM/whatever feed
(This process is for wordpress but you should be able apply the same concept to your blog/site software)
Edit the following files (wordpress): wp-rss2.php, wp-rss.php, wp-atom.php, wp-rdf.php and wp-commentsrss2.php, and write the following line at the top (after < ? php)
where yourscript.php is the script that you made.
So, who/what accessed my RSS feed lately?
- Feedfetcher-Google; (+http://www.google.com/feedfetcher.html)
- Akregator/1.2.5; librss/remnants
- Mozilla/5.0 (X11; U; Linux i686; en-US; rv:220.127.116.11) Gecko/20061201 Firefox/18.104.22.168 (Ubuntu-feisty)
- msnbot/1.0 (+http://search.msn.com/msnbot.htm)
- Mozilla/5.0 (compatible; Yahoo! Slurp; http://help.yahoo.com/help/us/ysearch/slurp)
- Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)
- Blogslive (email@example.com)
- Feedster Crawler/3.0; Feedster, Inc
- http://www.relevantnoise.com; firstname.lastname@example.org
- Mozilla/5.0 (compatible; Google Desktop)
- You can edit only wp-feeds.php and add the include to that script, but if someone/something directly subscribes to a specific output (e.g. atom) then they may not register, this is why I added the include to all the feed outputs
- Yes there are some services which allow you to get stats for your scripts but you would have to generate the script via that service/web site which seems cumbersome - this method allows you to get the stats directly
- The code can be improved, I know.
- Another idea would be to output the log in a proper format that a statistics software would recognise so you can get nice graphs/stats/proper analysis
2 comments January 24th, 2007