seco Posted February 17, 2008 Share Posted February 17, 2008 Hi i insert data to my db correctly but when i go to some page and them return to the insert page again a message appear prompts me if i want to send the post data again and if ok it will insert te data again to the db how to prevent data insertion only if the page is not posted back? thanks in advance. Link to comment https://forums.phpfreaks.com/topic/91499-how-to-prevent-data-insertion-when-the-page-is-post-back/ Share on other sites More sharing options...
Chris92 Posted February 17, 2008 Share Posted February 17, 2008 What you could try is store the refering link into a session, something like this: <?php session_start(); if($_SESSION['referer'] == "http://{$_SERVER['HTTP_HOST']}{$_SERVER['REQUEST_URI']}") { die("please do not go back"); } $_SESSION['referer'] = $_SERVER['HTTP_REFERER']; ?> I'm not sure if this will work but it's worth a try. Link to comment https://forums.phpfreaks.com/topic/91499-how-to-prevent-data-insertion-when-the-page-is-post-back/#findComment-468718 Share on other sites More sharing options...
Rithiur Posted February 17, 2008 Share Posted February 17, 2008 A better idea would be store a session variable in the form page and also insert that same variable into the form. When the form is submitted, you check if the submitted variable in the form is the same as the one stored in the session. If it matches, you insert the new data, and if it doesn't, you give out some sort of error. Once the data has been inserted into the database, simply remove the session variable or save a new value into it, so that attempting to resubmit the same form will not be accepted. Link to comment https://forums.phpfreaks.com/topic/91499-how-to-prevent-data-insertion-when-the-page-is-post-back/#findComment-468720 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.