2014-02-19

Level Up - Webmaster: How To Randomly Redirect Visitors To Different Websites

There is a very simple method using PHP to have visitors automatically redirected to another site.

Why this is useful:
- User clicks "Take me to a random" page. You can finely-tune the random outcome.
- You are doing some A/B testing and want to sent users to different locations to test.
- Or, like me, you want to share your various websites/games, from a single button.

Try clicking
Ex: http://apps.simplyadvanced.net/windows8/redirect

Step 1: Here's all the PHP code that you need:

$urls = array("siteA.com",
              "siteB.com",
              "www.example.com"); $url = $urls[array_rand($urls)]; header("Location: http://$url"); ?>

Step 2: Done

Or, if you want to redirect the visitor after they visit a certain URL on your domain, then simply create an "index.php" file in the public directory that you want users to be redirected from, then the above code is all that you need to put in it.

Try it: Random Windows 8 Games created by me.
Try it: Random Windows Phone Games created by me.

~ Danial Goodwin ~



No comments: