How to display the Last 10 Referrers list
A few folks have asked how I did the last 10 referrers list that appear over on the right-hand side of all the pages on my site. Well, here it is.
The first thing you need to know is that every page on Dave’s Picks goes through a PHP script to render the page. There’s more about that in About Dave’s Picks. That script includes the following code near the beginning, which saves off every referrer to a minimally formatted HTML file (which is defined right near the top).
$REFFILENAME = “/usr/webstuff/davespicks_reffile.html”;
if (isset($HTTP_REFERER) &&
($HTTP_REFERER != “”) &&
($HTTP_REFERER != “bookmarks”) &&
($content != “addpick.php”))
{
// I have a referrer I want to save — save it to the file
$shortref = preg_replace(”/http:\/\//”,”", $HTTP_REFERER);
$shortref = preg_replace(”/\/.*/”, “”, $shortref);
if (($shortref != “davespicks.com”) &&
($shortref != “www.davespicks.com”) &&
($shortref != “bookmarks”))
{
// quote the &s in URLs to make legal HTML
$longref = preg_replace(”/&/”, “&”, $HTTP_REFERER);
$reffile = fopen($REFFILENAME,’a');
fwrite($reffile, “<a href=\”$longref\”>$shortref</a><br>\n”);
fclose($reffile);
}
}
Since I’m using the template class from PHPLib to do text-substitutions into a standard template, I just have an entry in the template where I plug in the referrers. I’m not going to try and describe how PHPLib templates work, but the following code gets the list that I plug in. I do this just before I emit the page.
// set up the last 10 referrers list
$refarray = array();
exec(”/usr/bin/tail $REFFILENAME”, $refarray);
$reflist = implode(”\n”, $refarray);
That’s about it. It’s made easier by the fact that I don’t need a complete HTML file (even though I call it davespicks_reffile.html) to store the referrer information. There’s probably a more efficient way I could be doing it than using tail over and over, but the server logs don’t show that heavy of a load from this part of the script, so I’m not worrying about it yet. Avoid Premature Optimizations. The only other thing is that the refs file is never cleared out by this script. I’ve got some perl scripts that run daily and clean things up for me, but that’s another article.
Read more in PHP.NET
Random Post
Related Articles
- How to create Shortlinks with Google Apps
- Auto post to Blogger with PHP
- How to use Adsense again if get banned
- Mechanisms against Spam Mail
- How to protect login on Wordpress admin ?
- How to submit your website on Microsoft
- How to setup POP3 Yahoo for business ?
- How to setup POP3 yahoo mail ?
- How to surf website by VPN
- How to setup Google Apps mail services
Recent Posts
- Free Panda Internet Security 2010: Windows 7 Launch Party
- FREE 1-year license of Kaspersky Internet Security 2010!
- Warning hack password Yahoo mail !
- How to Use Western Union quick cash at Google Adsense ?
- Western Union available in VietNam
- Facebook for Nokia phones
- DailyMotion now offering Embed HD Video Players
- Free Adword voucher $50
- How to create Shortlinks with Google Apps
- Auto post to Blogger with PHP
- Free Auto Blogger: Auto post rss feed
- The Google Analytics API and PHP
- Using the Google Analytics API - getting total number of page views
- Google Analytics PHP API class
- Blogger team warning Spam posts
- Adsense launching “Category filter Beta”
- Alternatives to Google Adsense by other programs
- What is Adsense Smart Price ?
- How to avoid Adsense Smart Pricing ?
- How to use Adsense again if get banned
Recent Comments
- Nancy
in Auto post to Blogger with PHP - Tony M J
in DailyMotion now offering Embed HD V… - fonfenVak
in Enable Ping track in wordpress - DaiVyCorp - Int…
in My Google AdSense Account Is Disabl… - DaiVyCorp - Int…
in My Google AdSense Account Is Disabl… - AlexAxe
in VPN Protocols - jennefoh
in Make more money: YouTube Videos Com… - GlenStef
in VPN Protocols - DaiVyCorp - Int…
in Why should I use proxy servers ? - Alexwebmaster
in VPN Protocols
Most Commented
- Top 10 ways to boost alexa ranking (4)
- How to Boost Alexa Ranking (4)
- VPN Protocols (4)
- Make more money: YouTube Videos Coming to AdSense (2)
- My Google AdSense Account Is Disabled (2)
- Top 10 secrets success with business online (1)
- SEO with Site Address / URL (1)
- Free Ways to Increase Your Blog Traffic (1)
- How to SEO wordpress, The Complete Guide (1)
- Manual Unzip Server Command (1)
Most Viewed Post
- Adsense launching “Category filter Beta” - 1,077 views
- How to SEO Copywrite - 990 views
- Top 10 ways to boost alexa ranking - 804 views
- How to Prevent Spam VBB with GeoIPCountry - 703 views
- SEO with Site Address / URL - 656 views
- Tutorial: IPSec Security structure - 653 views
- Invalid Clicks Contact Form: How to contact to Google Adsense support Team - 652 views
- Auto post to Blogger with PHP - 652 views
- Youtube with google adsense - 600 views
- Warning hack password Yahoo mail ! - 585 views
Categories
- How to (51)
- SEO (33)
- Google adsense (31)
- Business land (13)
- Security Policies (21)
- Tips (26)
- Technology news (7)
- Traffic guide (9)
- Top secrets MMO (6)
- Tutorials (10)










No Comment
Leave Your Comments Below