/    Sign up×
Community /Pin to ProfileBookmark

checking if a "refresh" was done!

how can i check if the user pressed “F5” (refresh?)
beacuse for example if he has filled out data in a table and after i hhave aupdated he presses F5 the update will be done again!
how can i find thatout and even prevent it?
thnaks i nadvance
peleg

to post a comment
PHP

1 Comments(s)

Copy linkTweet thisAlerts:
@NogDogJun 06.2005 — I don't know of anyway to trap that on the server side.

What you can do is create a hidden field in your form and set its value to a unique ID using PHP's uniqid() function. When the form-handler receives the form data, it can store that ID in a session variable, and check subsequent requests for a duplicate ID and reject it if so:

Form:
[code=php]
<input type=hidden name=id value="<?php echo uniqid() ?>">
[/code]

Handler:
[code=php]
<?php
session_start();
if(isset($_SESSION['id']) and $_SESSION['id'] == $_POST['id'])
{
echo "<p>ERROR: Transaction already processed. Please do not resubmit the formn";
echo "or refresh the page.</p>n";
}
else
{
$_SESSION['id'] = $_POST['id'];
# do your form processing here.
}
?>
[/code]
×

Success!

Help @pelegk1 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.15,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...