Reputation: 85
I have done some research on this and discovered the rand(), srand(), and mt_srand() yet they don't work too well for me.
I want PHP to generate a random ID (number) and then have it stay that way no matter how many times you refresh the page. I suppose this could be done with incrementing operators or session variables? Cookies perhaps?
Upvotes: 0
Views: 103
Reputation: 96
One way to do it with sessions for a random number between 42 and 1337:
session_start();
$random_nb = $_SESSION['random_nb'] ?: ($_SESSION['random_nb'] = mt_rand(42, 1337));
echo $random_nb;
Upvotes: 1