ryeman98 Posted July 24, 2007 Share Posted July 24, 2007 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. Quote Link to comment Share on other sites More sharing options...
teng84 Posted July 24, 2007 Share Posted July 24, 2007 use session then do the increment "++" Quote Link to comment Share on other sites More sharing options...
ryeman98 Posted July 24, 2007 Author Share Posted July 24, 2007 Err... I would have to unset the session on a different page then, wouldn't I? The game keeps going back to the same page because it's just easier to manage Quote Link to comment Share on other sites More sharing options...
btherl Posted July 24, 2007 Share Posted July 24, 2007 We can't give you any more detailed help unless you describe your game's structure in more detail. You can reset the session counter any time you want. Just $_SESSION['counter'] = 0. Quote Link to comment Share on other sites More sharing options...
ryeman98 Posted July 24, 2007 Author Share Posted July 24, 2007 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... Quote Link to comment Share on other sites More sharing options...
btherl Posted July 24, 2007 Share Posted July 24, 2007 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. } Quote Link to comment Share on other sites More sharing options...
ryeman98 Posted July 24, 2007 Author Share Posted July 24, 2007 I'm not sure if I fully understand. If a user guesses and goes to the "result" page, which shows both guesses and who wins, if they press refresh, it will still add points because the session doesn't get reset. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.