Pretty short script. Use the built-in PHP function mt_rand($min, $max)
.
if (mt_rand(0,1) == 0) {
header('Location: http://example.com/redirect1/');
exit;
} else {
header('Location: http://example.com/redirect2/');
exit;
}
Or as a ternary, which can be a little less readable if not using variables:
header(mt_rand(0,1) == 0 ? 'Location: http://example.com/redirect1/' : 'Location: http://example.com/redirect2/');
exit;
Or using variables:
$redirect1 = 'http://example.com/redirect1/';
$redirect2 = 'http://example.com/redirect2/';
header('Location: ' . mt_rand(0,1) == 0 ? $redirect1 : $redirect2);
exit;