<?php $urls[] = "http://www.google.com"; $urls[] = "http://www.ebay.com"; srand ((double) microtime( )*1000000); $random = rand(0,count($urls)); header("location:" . $urls[$random]); exit; ?> It's a random rotation. I need to add a percentage priority to the url. ie: 80% to url1, 20% to url2. This will make the url1 to rotate 80% of the time... if you have a similar script or can help about what I need, feel free to post thx.
just add array elements with the element you want! so if you have an array with 5 values from which 4 are google.com then the chance of it showing up is 80% compared to the 20% of ebay.com. This is a simple and effective way for implementing this but if you have too many URLs and want to have more precised percentages(i.e 73% and 27%) you might want to try a more complex algorithm.
I'm not sure if this is what your looking for, but I just quickly made it and tested it briefly and it seems to work fairly well. <?php $url = array("20" => "http://google.com/", "40" => "http://forums.digitalpoint.com/", "100" => "http://blakeembrey.com/"); $random = rand(1, 100); $closest = 100; foreach($url as $k => $u) { if($k <= $closest && $random <= $k) { $show = $u; $closest = $k; } } echo $show; ?> This way you just set the value before the url to the percentage you want. The only problem here is that you have to actually calculate it yourself when you type it in. It probably isn't the ideal solution, but it's all I can think of at the moment that will actually work to the exact perentage. E.g. The solution above will have a 20% chance of drawing google.com, a 20% chance of drawing the forums and a 60% chance of drawing my website.
Yeah Sorry I dont have a more elegant solution, but I can't think of one at the moment. I'll keep thinking