Posted by Martin Porcheron
This article was initially written on the 17th December 2006, it was last updated on 22nd of May 2007.
Ok, so you’ve spent ages building your website, put quite a bit of money into the hosting and then to top it off, you write a gripping article that circulates around major websites like a disease. Your server gets hammered by thousands of geeks trying to read what you wrote, but your poor little server that you thought was reliable turns out it can’t handle and swarm of people all at once.
Luckily, there are caching services available that are free. One of the most notable is the Coral Content Distribution Network. They provide a cached version of your webpage so that when your website goes down, people can still access it. But why should you wait until your server is attacked before your users start using the cache? This script will automatically send users, who come from a high-traffic website, to the Coral cache of the requested page. Neat, huh?
Information/Background
The idea behind this script came from Digg defender by Elliot Back. Sadly, Elliot’s script is only a WordPress plug in, and well, Word Press blogs aren’t the only websites that can experience high traffic. Although I wrote this script myself, the credit for the idea does reside with Elliot. Note: At the time of writing this script, I was using a custom CMS for the website however as of recently I have switched to WordPress.
License
This script is licensed under GNU GPL Version 2.
Source code
<?php
$sites = Array(
'digg.com',
'slashdot.org',
'reddit.com',
'fark.com',
'somethingawful.com',
'kuro5hin.org',
'engadget.com',
'boingboing.net',
'del.icio.us',
'netscape.com'
);
if (isset ($_SERVER['HTTP_REFERER']) && !strstr ($_SERVER['HTTP_USER_AGENT'], 'CoralWebPrx'))
{
$referer = parse_url ($_SERVER['HTTP_REFERER']);
$referer = $referer['host'];
foreach ($sites as $site)
{
if (stristr ($referer['host'], $site))
{
header ('Location: http://'. $_SERVER['HTTP_HOST'] .'.nyud.net:8080'. $_SERVER['REQUEST_URI']);
exit;
}
}
unset ($sites);
unset ($referer);
unset ($site);
}
?>
<?php
$sites = Array(
'digg.com',
'slashdot.org',
'reddit.com',
'fark.com',
'somethingawful.com',
'kuro5hin.org',
'engadget.com',
'boingboing.net',
'del.icio.us',
'netscape.com'
);
if (isset ($_SERVER['HTTP_REFERER']) && !strstr ($_SERVER['HTTP_USER_AGENT'], 'CoralWebPrx'))
{
$referer = parse_url ($_SERVER['HTTP_REFERER']);
$referer = $referer['host'];
foreach ($sites as $site)
{
if (stristr ($referer['host'], $site))
{
header ('Location: http://'. $_SERVER['HTTP_HOST'] .'.nyud.net:8080'. $_SERVER['REQUEST_URI']);
exit;
}
}
unset ($sites);
unset ($referer);
unset ($site);
}
?>
Usage
To use this code, simply include it above all the PHP code in your website. You must make sure there is no output (including whitespace) otherwise the script will fail when it comes to redirection.











Galicia (Spain)





