TecTao Posted April 5, 2007 Share Posted April 5, 2007 This may be a question that I have the answer to being a mid-level PHP programmer but I don't. I have a form page. When submitted it posts to page2. On page 2, it inserts variable into the database. The queries the database and displays the information. But.... If the viewer refreshes their browser, it now submits the information into the database again. Not sure how to handle problem. I think that if a session variable passed to page 2 in an if else statemen, it will keep this from happening when refreshed since the session variable is not passed in the refresh. But I'm stuck. Link to comment https://forums.phpfreaks.com/topic/45765-double-input-of-form-data-when-browser-is-refreshed/ Share on other sites More sharing options...
Wildbug Posted April 5, 2007 Share Posted April 5, 2007 I had this problem when first programming with PHP and form submission like you're doing. What worked for me was to redirect the browser after submitting the data, then the data will not be submitted again if the user reloads the browser. For instance: session_start(); // Your input validation code... // If data is valid, save it, then: header("Location: http://...newlocation"); exit; // Otherwise, chastise the user and ask them to correct it.... or not. Link to comment https://forums.phpfreaks.com/topic/45765-double-input-of-form-data-when-browser-is-refreshed/#findComment-222292 Share on other sites More sharing options...
kid_drew Posted April 5, 2007 Share Posted April 5, 2007 I just solved this one recently myself. Post to yourself, process the post, and redirect with a header to a confirmation page. This may be a question that I have the answer to being a mid-level PHP programmer but I don't. I have a form page. When submitted it posts to page2. On page 2, it inserts variable into the database. The queries the database and displays the information. But.... If the viewer refreshes their browser, it now submits the information into the database again. Not sure how to handle problem. I think that if a session variable passed to page 2 in an if else statemen, it will keep this from happening when refreshed since the session variable is not passed in the refresh. But I'm stuck. Link to comment https://forums.phpfreaks.com/topic/45765-double-input-of-form-data-when-browser-is-refreshed/#findComment-222310 Share on other sites More sharing options...
boo_lolly Posted April 5, 2007 Share Posted April 5, 2007 i ran into this same problem recently. i tried everything in my power to delete the $_POST array. for example: foreach($_POST as $key => $val){ unset($key); } but nothing worked. i found out that $_POST is also handled by your browser, so it's much more difficult to get around. one way is the way you've stumbled upon. basically redirecting to a new page. Link to comment https://forums.phpfreaks.com/topic/45765-double-input-of-form-data-when-browser-is-refreshed/#findComment-222348 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.