Easily Redirect To A Random URL Using PHP
June 29, 2009 · 35 Views · Filed Under Scripts
Using the code below, you can send a visitor to one URL and then have them redirected to a random URL. All you have to do is open notepad, copy the code below, change the addresses and then save it as “whatever.php”. You can also add more addresses by adding more lines and changing the number.
<?php $url[0] = "http://www.google.com"; $url[1] = "http://www.yahoo.com"; $url[2] = "http://www.47movies.com"; srand ((double)microtime()*1000000); $randomnum = rand(0, count($url)-1); header ("Location: $url[$randomnum]"); ?> |
Right now, I’m using this to redirect visitors to a random sponsor on a website that I recently closed down. I redirect all 404s to the index of the site using htaccess and then the index.php file contains the random redirect.
Comments
Leave a Reply








