View Single Post
Old 09-21-2009, 11:47 PM  
GrouchyAdmin
Now choke yourself!
 
GrouchyAdmin's Avatar
 
Industry Role:
Join Date: Apr 2006
Posts: 12,085
Here's a real simple way to do it:

Code:
<?php
$urlArray = array(
  "http://whatever",
  "http://whatever",
  "http://whatever",
  "http://whatever",
  "http://whatever",
  "http://whatever",
  "http://whatever",
);

header("location: ".$urlArray[mt_rand(0, count($urlArray)-1)]);
?>
This doesn't do that great for weighting.

If you want to do some weighting, some pseudo code (ugly) could be as follows:

Code:
$count = ceil(100/count($urlArray));
$randchoice=rand(count($urlArray)%$count,0)-1;
Never did bother checking the graulatity of the above code snippit in practice, though, though. It should give roughly an even (rounded up) percentage to either one, since PHP's rand() tends to suck with smaller subsets.

Make DAMN sure you just use a location: redirect, which is a 301. Google won't penalize you for those.
__________________

Last edited by GrouchyAdmin; 09-21-2009 at 11:48 PM..
GrouchyAdmin is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote