Jump to content

[SOLVED] Prevent a refresh using PHP?


galvin

Recommended Posts

I have a site where a form action enters information into a MySQL table.  And if someone submits the form and then refreshes the page, it will enter duplicate info into the MySQL table.

I'd like to prevent this as it will skew my data.

 

Is there a way to prevent someone from refreshing a certain page?  Like maybe a way where if someone hits REFRESH on a certain page, it redirects them to the HOME page?

 

 

Link to comment
https://forums.phpfreaks.com/topic/150963-solved-prevent-a-refresh-using-php/
Share on other sites

Don't start a second session, just give the page a unique session variable, it will then monitor the variable, the first time the user comes to the page that variable gets 1, the second time if the variable isset() then they have refreshed the page so redirect them and do not enter any information in the database.

<?php
if(!isset($_SESSION['Unique'])) {
    //first visit
    $_SESSION['Unique']  ;
}
else {
    //second visit
    header('Location: index.php');
    exit;
}
?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.