I am trying to generate a random number (between 1 - 151) so I can open a page based on a randomly generated ID. The issue here is with browser compatibility because the intended functionality works on Edge but no Chrome or FireFox.
pokedex.php:
<form action='randomPokemon.php' >
<button type="submit" class="toolsBtn">Random</button>
</form>
randomPokemon.php:
<?php
$host = $_SERVER['HTTP_HOST'];
$uri = rtrim(dirname($_SERVER['PHP_SELF']), '/\\');
$extra = 'pokedex.php?pid=';
$randomid = rand(1, 151);
header("HTTP/1.1 303 See Other");
header("Location: http://$host$uri/$extra" . mt_rand(1, 151));
unset($randomid);
exit;
?>
Live Demo at: http://fraserprovan.co.uk/projects/pokedex/pokedex.php
I have no idea why it works on Microsoft Edge but not other browsers. On chrome it opens the same page everytime as if the varaible $randomid doesnt change. Any advice or links to other resources will be greatly appreciated.
UPDATE: decided to do it in Javascript instead using the following function, Thanks for the suggestions.
function randomPokemon(){
var randomNum = Math.floor(Math.random() * 151) + 1;
document.location.replace('pokedex.php?pid=' + randomNum);
}