RonInNewYork Posted May 3, 2011 Share Posted May 3, 2011 I'm learning PHP, and in the course of this, I'm writing a little app which posts to the same php file. HOWEVER, when I run the app again, the POST values remain. I can use unset() but, is there another way to clear POST data? RON Quote Link to comment https://forums.phpfreaks.com/topic/235427-test-post-clearing-the-post-cache/ Share on other sites More sharing options...
RonInNewYork Posted May 3, 2011 Author Share Posted May 3, 2011 I'm testing with Chrome. I am writing a directory search program and when I choose the directory (just a text input box) I post this back to the same app: <form action="tedit.php" method="POST"> <div style="width:30em;"> <label for="directory">Directory to Search</label> <input type="text" name="directory" id="directory" value=""/> <div style="clear:both;"> <input type="submit" name="submitButton" id="submitButton" value="Submit"> </div> </div> </form> and when I process the post, I look at $_POST["submitButton"] and $_POST["directory"]. However, as is the case now, when the directory is nonexistent, I cannot figure out how to get rid of this data. I've tried unset() and $_POST["directory"]=""; but neither seems to work. RON Quote Link to comment https://forums.phpfreaks.com/topic/235427-test-post-clearing-the-post-cache/#findComment-1209916 Share on other sites More sharing options...
PFMaBiSmAd Posted May 3, 2011 Share Posted May 3, 2011 The problem occurs because the recorded information in the browser's history for the URL is a form submission. When you navigate back to that URL or refresh the page the browser attempts to perform the action it has recored for that URL. There are two things you can do to fix this - 1) After you have successfully processed the form submission, redirect to the same URL. This will cause a GET request for that URL to be recored in the browser's history and it won't resubmit the form data when you navigate back to that URL. 2) Store a value in a session variable that indicates that the form has been processed and skip the form processing code as long as that session variable is set. Quote Link to comment https://forums.phpfreaks.com/topic/235427-test-post-clearing-the-post-cache/#findComment-1209919 Share on other sites More sharing options...
RonInNewYork Posted May 3, 2011 Author Share Posted May 3, 2011 THANKS!! That will help. RON Quote Link to comment https://forums.phpfreaks.com/topic/235427-test-post-clearing-the-post-cache/#findComment-1209924 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.