Page 1 of 1

Prevent going back [SOLVED]

Posted: Sat Jul 09, 2011 6:09 pm
by 62896dude
Hey there everyone

So I have a question that I am sure someone here has the answer to, but no matter how hard I look online, there doesn't seem to be a complete answer as to how to accomplish what I need it to. So I was wondering, how exactly do I prevent the user from going back a page? Let's say that they fight a monster, die, and are shown the screen that says for example "You died n00b, <a href="whatever.php"go back to the index page with less money and half health</a>" (I only included the <a href> tag to show where the link would be. Well my problem is, the user could just say "heh, silly game, I shall now press the back button and try again" and so they do, and nothing is stopping them. So how do I prevent them from doing this? And if I can't deny them from going back a page, how can I make it so that if they try to go back, it just keeps them on the same page they were on before?

Thanks everyone!

Re: Prevent going back

Posted: Sat Jul 09, 2011 7:18 pm
by Torniquet
When i was dealing with fighting etc on my first game i started, i had a flag in the database which indicated whether i was in a fight or not. When a player ran or died, the flag would turn off, and if they tried to go back and do something, they would be sent to another page or a message would display saying they weren't in a fight.

so right at the top of the page you want to run a check to see if this flag is set to on or off, if on then the fight continues, if off then throw them from the page.

I would handle the death consequences the moment they are killed as well so they cant log off and log back on without anything happening.

Re: Prevent going back

Posted: Sat Jul 09, 2011 7:26 pm
by 62896dude
That is a very good idea! I will likely use that in my battles. However, would I just have to do the same thing in every other page? Because I don't think I want the back button used at all

Re: Prevent going back

Posted: Sat Jul 09, 2011 7:56 pm
by Torniquet
i dont quite understand what you mean. I dont think there is anyway of disabling the back button, but you can formulate alot of restrictions using that method.

setting up flags (or a single field which indicates the players current status, such as in battle, cooking, flying etc) can force people to various pages and stopping them from making certain actions while these flags are set.

Re: Prevent going back

Posted: Sat Jul 09, 2011 7:58 pm
by 62896dude
Okay, I'll just make it work with the way you showed me then, thanks for the help! :)