Jump to content

Php Random


ChidoriSoul
 Share

Recommended Posts

Ok, so I am trying to make a basic well, treasure hunt, in PHP. I would want it to have so that it would be on the same page, and every time you click search, it generates the same page, excpet with a different outcome.Also, it could not be where people could not just change the link in the address bar so they could find the answer immediatlly

Link to comment
Share on other sites

If the users are logging in before they start the treasure hunt, you can use the $_SESSION to keep track of their attempts.To generate the random number, you can use mt_rand() with proper min and max values of course.You should also have a condition whereby if they've already tried that number, it tries to generate one again.To do all that, you can use something like:

$makeAttempt = true;$attempt;while($makeAttempt) {	$attempt = mt_rand(0, 15);//assuming you have 15 possibilities	$makeAttempt = in_array($attempt, $_SESSION['attempts']);}$_SESSION['attempts'][] = $attempt;

Link to comment
Share on other sites

Ok, now how can I customize the each prize to a page
With the session again. Have two separate variables telling the price, and it's right number. Then verify the attempt against the right number, and give the price if correct.The point is - everything that must be preserved across requests - store it in the session.
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...