galvin Posted March 24, 2009 Share Posted March 24, 2009 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 More sharing options...
WolfRage Posted March 24, 2009 Share Posted March 24, 2009 You can start a session when the user comes to the page and set it to add 1 to a variable. If the variable equals two then they have refreshed so redirect them. Link to comment https://forums.phpfreaks.com/topic/150963-solved-prevent-a-refresh-using-php/#findComment-793136 Share on other sites More sharing options...
galvin Posted March 24, 2009 Author Share Posted March 24, 2009 I already started a session when they first start on the home page that lasts throughout their visit. Is it possible to start a 2nd, separate session? (I know, probably a dumb question, but I'm a newbie) Link to comment https://forums.phpfreaks.com/topic/150963-solved-prevent-a-refresh-using-php/#findComment-793142 Share on other sites More sharing options...
WolfRage Posted March 24, 2009 Share Posted March 24, 2009 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; } ?> Link to comment https://forums.phpfreaks.com/topic/150963-solved-prevent-a-refresh-using-php/#findComment-793148 Share on other sites More sharing options...
galvin Posted March 24, 2009 Author Share Posted March 24, 2009 Beautiful, think I got it now. Thanks! Link to comment https://forums.phpfreaks.com/topic/150963-solved-prevent-a-refresh-using-php/#findComment-793157 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.