Though you're dancing all around it, there's a lot wrong there.
$a isn't changed by
array_rand, so it's still an array, but then
if ($a='/ts') sets it (to test it you need two equal signs == just one = sets it) to
/ts in a "truthy" fashion (all setting of non false values resolves as true to the boolean parser), so
header("Location: /ts"); exit(); will always happen.
You can actually work this out with array_rand, but as I was looking at the man page, it was suggested there was a better method, mt_rand (said to be faster and closer to truly random). It works a little differently. In any case, this does the trick:
PHP Code:
<?php
$a = array("/ts", "/ts2");
header("Location: " . $a[mt_rand(0, count($a) - 1)]);
die();
?>
Now random is random though, and you only have two choices, so sometimes you will get the same result a few times or more in a row. Ten is unlikely, but could happen. Even 100, though that's very unlikely. In fact, after just 20 or so tries, you should be seeing it go to one about half the time, and the other the rest of the time. I tried both methods (array_rand and mt_rand), and the mt_rand method seemed more evenly distributed.
Bookmarks