Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using $_POST information only once

Tags:

php

I have some information which gets passed from a form and needs to be used once and only once. I can collect it nicely from $_POST but I'm not sure which is the "best" way to ensure that I can only use it once, i.e. I want to avoid the user pressing F5 repeatedly and accessing the function more than once.

My initial thought was to set a session variable and time the function out for a set period of time. The problem with that is thay could have access to the function again after the set period has elapsed.

Better ideas welcomed!

like image 649
user114671 Avatar asked May 20 '26 15:05

user114671


2 Answers

A redirect to another page would be sufficient to break most browser repost-on-refresh behaviour. Setting a cookie on form submit (or a session variable, as you suggest) would also work quite nicely. You could have the form submission page unset the session variable again, such that only a fresh access to the form would permit re-submitting the form.

like image 194
Gian Avatar answered May 23 '26 07:05

Gian


This one's VERY easy to implement.

All you need to do is this:

have your form submit to a different page, which will only handle the post information, and not display ANYTHING

Then, send a LOCATION header to redirect the browser to a new page (which will be retreived by GET) This will break the browser's repost-on-refresh behaviour

like image 31
Pranav Hosangadi Avatar answered May 23 '26 05:05

Pranav Hosangadi