Submitted by Jan Polzer on April 20, 2008 - 1:07pm
Website owners using Drupal have a very detailed log of access available directly in their admin pages. However there is no built-in functionality which could show how many RSS subscribers does the website have. You have all the neccessary information available in the log. So only thing you have to do is to find them and to show them. I will show you how to prepare a block that will inform you and your readers about current RSS subscribers count.
RSS subscribers block in Drupal
So at first, create a new block and set up its input format to the PHP code. You should input a few sentences to your readers about RSS. Then prepare the most important part of this work - SQL command:
<?php
$rssreaders = db_fetch_array(db_query("SELECT COUNT(DISTINCT(hostname)) AS hostname FROM {accesslog} WHERE path LIKE '%/feed' OR path LIKE 'rss.xml'"));
?>
This command will count all RSS hits to the URL's ending by /feed or to rss.xml page. The DISTINCT keyword will manage to count every IP in the accesslog only once. Then you have to print the value in $rssreaders['hostname'] somewhere:
<p>Follow other readers and <a href="/rss.xml">subscribe</a> to our <a href="/rss.xml">RSS feed</a>. Currently we have <b><?php print $rssreaders['hostname']; ?></b> RSS subscribers now.</p>
So the result content of your block should look like this:
<?php
$rssreaders = db_fetch_array(db_query("SELECT COUNT(DISTINCT(hostname)) AS hostname FROM {accesslog} WHERE path LIKE '%/feed' OR path LIKE 'rss.xml'"));
?>
<p>Follow other readers and <a href="/rss.xml">subscribe</a> to our <a href="/rss.xml">RSS feed</a>. Currently we have <b><?php print $rssreaders['hostname']; ?></b> RSS subscribers now.</p>
I have use this block on my websites Backup HowTo and Photo HowTo - take a look if you are interested.
Comments
Thanks.Your blog is useful.
Permalink Submitted by recykling (not verified) on June 11, 2008 - 10:31am.
Thank you very much
Permalink Submitted by PHP Development... (not verified) on August 8, 2008 - 4:32am.
RSS Subscribers in Drupal
Permalink Submitted by Software Develo... (not verified) on November 25, 2008 - 7:56am.
Innacurate number
Permalink Submitted by Jaako (not verified) on January 17, 2009 - 2:42pm.
Re: Innacurate number
Permalink Submitted by Jan Polzer on January 24, 2009 - 9:50pm.
Correct statement
Permalink Submitted by Frank (not verified) on April 25, 2010 - 10:56am.
I read your article as I want do have such a statistic, too. I played a bit with the SQL and I filtered all out, that just hit twice or less:
SELECT COUNT(hostname) AS hostname FROM (SELECT hostname FROM `accesslog` WHERE path LIKE '%/feed' OR path LIKE '%rss.xml' GROUP BY hostname HAVING COUNT(*) >2 ) AS logYou will still count dial up accounts or users with changing ip address more than once...
Re: Correct statement
Permalink Submitted by Jan Polzer on April 25, 2010 - 2:12pm.
There's a module for that
Permalink Submitted by Anonymous (not verified) on June 15, 2010 - 2:23pm.
Thanks
Permalink Submitted by boykie (not verified) on December 27, 2010 - 1:37pm.