Jump to content

Possible to detect refresh?


ryeman98

Recommended Posts

Hi! I'm making a game and I want to be able to detect if a user refreshes, and if they do, I want to reset the score to 0. I know how to reset the score, I just need to know if you can somehow detect if they refreshed the page.

Link to comment
Share on other sites

The game is rock, paper, scissors.

 

I use sessions for the guesses. The computer's guess is random and is a session instead of a hidden input (because if you view the source code, you can see the computer's choice) It starts out at rps.php?action=play and then after the guess, it goes to rps.php?action=round which is where if the user presses refresh, the computers choice will change, causing the user to cheat...

Link to comment
Share on other sites

Ok, makes sense.  Does it really matter if the user refreshes, since the user never knows what the computer has guessed?  If you don't want the guess to change, you could do something like this:

 

if (user made a guess) {

  Check guess

  Update score

  Generate new guess

} else {

  Do nothing.  Keep the old guess.

}

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.