There's three things to note about this.
header()
should not be echo
'ed, it returns void
.
array_rand()
will just return the key of an element, not the value.
- You should always use
exit;
after header("Location: ..");
(although it might not be relevant if its the end of the script).
From the manual (emphasis mine)
Picks one or more random entries out of an array, and returns the key (or keys) of the random entries.
After implementing those changed, your code would look like this
$input = array("https://order.abcgameservers.com/aff.php?aff=47", "https://discord.gg/CjzZRBq");
$answer = $rand_keys = array_rand($input);
header('Location: '.$input[$answer]);
exit;
You'll notice that the header()
has been altered in two ways: The echo has been removed (and the quotes that went along with that), and that it targets $input[$answer]
instead of $answer
.
Alternatively, you can use array_flip()
to flip the value/index pairs. If you use array_rand()
on that, you'd get a random value!
$answer = array_rand(array_flip($input));
header('Location: '.$answer);
exit;