Redirecting Specific IP’s to Other Websites Using PHP

Someone had requested a script that would redirect a list of ip’s to a random list of sites.

Here’s the snippet I came up with:

<?
// list of ip's you wish to redirect
$ips = array('127.0.0.1');
// Sites you wish to redirect to
$sites = array('http://yahoo.com/','http://www.aol.com');
 
foreach($ips as $ip) {
    if ($ip==GetHostByName($REMOTE_ADDR)) {
        header('Location: ' . $sites[rand(0,count($sites))]);
    }
}
?>
Share and Enjoy:
  • Digg
  • del.icio.us
  • Netvouz
  • DZone
  • ThisNext
  • MisterWong
  • Wists
  • blogmarks
  • BlogMemes
  • Furl
  • NewsVine
  • Reddit
  • SphereIt
  • Spurl
  • StumbleUpon
  • Technorati
  • YahooMyWeb

Leave a comment

Please be polite and on topic. Your e-mail will never be published.