0
Good evening guys, I am creating an online game where the user has the option to use an item to recover HP. When you click consume, an Alert appears on the screen stating that the item has been consumed and that HP has been recovered.
The problem, as you can imagine, is that every time I hit F5 the HP keeps increasing and the Alert appears again. I tried to use unset($_POST['']) to clean what was chosen by the user but did not work.
Thanks in advance for the help.
Ideally, a POST request should never have an HTML page as an answer, precisely because of this problem. The correct thing would be for you to set the header
Location
and redirect the customer back to the original page.– Woss
It is that this requisition happens in the "main page" of the game: tavern.php. Consuming the item that recovers HP is one of the functions available on this page, so ideally after consuming the item the user stays on that page, understand?
– Anderson S. Passos
This doesn’t change anything, you can redirect it to yourself, but no post.
– Bacco
Can you tell me how to do that?
– Anderson S. Passos
Exactly, making the
Location
for the same page, the client will make a GET request and not a POST.– Woss
There are 5 links at the close of the question, there are more detailed what you need.
– Bacco
Okay, thanks for the personal help, I think I get it
– Anderson S. Passos
It would be even better to send it to a "get.php" that redirects to the "tavern.php" back, so it confuses the code less. (the user will not see this "gets.php" pq will already be sent back with
header( 'Location: /recebe.php');die();
– Bacco
An empty page that would only have a redirect to the main page?
– Anderson S. Passos
Exactly, this would only have PHP to save to DB or process the data, and the Location header. Read this link here, it may help if you find a headers error: https://answall.com/questions/4251/70
– Bacco
This mistake was the first I found when I started, I created my account here just to find out how to solve it hahahahaha. Thank you so much for your help, I understand what I have to do
– Anderson S. Passos