thara Posted January 19, 2013 Share Posted January 19, 2013 Hope someone help me out about this problem.. I have a form to select user needed categories from it. I use check boxes for this form to let them to select categories. At the time they selected categories I am saving that selected categories on SESSION and after that category page redirect to the next page. That process is something like this... if ( $totalCategory >= 1 && $totalCategory <= 10 ) { $_SESSION['category'] = $_POST['category']; $url = BASE_URI . 'select_subject.php'; // Define the URL: header("Location: $url"); exit(); // Quit the script. } My problem is when category (after category select) page redirect to the next page (select_subject.php) sometimes user may need to go back to the category page again using clicking back button on browser to change again their selected category. But when it happen, it is not going to category page again and browsers display an error something like this... Document Expired,This document is no longer available. NOTE: But when I click page reload button page display properly. With this case I need to help from someone to avoid from this and I need to display category page again with displaying previously selected categories properly.. Hope someone help me out.. Thank you.. Quote Link to comment https://forums.phpfreaks.com/topic/273357-how-i-prevent-from-this-problem/ Share on other sites More sharing options...
BagoZonde Posted January 20, 2013 Share Posted January 20, 2013 I can't tell you how to use it with $_SESSION as I'm using for these purposes sessionStorage in Javascript. It save all my inputs selected (select, checkbox etc.) so when I'm going backwards or reloading page: I'm getting and setting all inputs from that automagically. Perhaps somebody knows better what to do in your case. Good luck! Quote Link to comment https://forums.phpfreaks.com/topic/273357-how-i-prevent-from-this-problem/#findComment-1407092 Share on other sites More sharing options...
Christian F. Posted January 21, 2013 Share Posted January 21, 2013 As far as I know this depends entirely upon your browser, and how it's set up. With Opera it simply reloads from cache, not sending anything to the server (unless the cache settings states otherwise), showing you exactly what you saw before pressing submit. Other browsers ask whether or not the post data, that was posted to create that page, should be re-submitted. Unless you've turned it off, which seems to be what you've done. You might be able to get around this by using GET, which you should if you're not adding data to your system when selecting categories. (Which it sounds like you're not.) Quote Link to comment https://forums.phpfreaks.com/topic/273357-how-i-prevent-from-this-problem/#findComment-1407251 Share on other sites More sharing options...
PFMaBiSmAd Posted January 22, 2013 Share Posted January 22, 2013 After you finish processing the POST data, you need to redirect to the exact same URL of the form processing page so that the last action the browser has for that URL is a GET request. Quote Link to comment https://forums.phpfreaks.com/topic/273357-how-i-prevent-from-this-problem/#findComment-1407399 Share on other sites More sharing options...
thara Posted January 22, 2013 Author Share Posted January 22, 2013 After you finish processing the POST data, you need to redirect to the exact same URL of the form processing page so that the last action the browser has for that URL is a GET request. can you please explain this little with an example? Thank you. Quote Link to comment https://forums.phpfreaks.com/topic/273357-how-i-prevent-from-this-problem/#findComment-1407416 Share on other sites More sharing options...
PFMaBiSmAd Posted January 22, 2013 Share Posted January 22, 2013 // if finished successfully processing submitted data, redirect to same url to clear post data if(empty($errors)){ header("Location:{$_SERVER['REQUEST_URI']}"); die; } Quote Link to comment https://forums.phpfreaks.com/topic/273357-how-i-prevent-from-this-problem/#findComment-1407502 Share on other sites More sharing options...
thara Posted January 23, 2013 Author Share Posted January 23, 2013 @PFMaBiSmAd.. your solution is ok. but problem is I need to redirect to anther page after form processing submitted data. Like this // If category form from category.php successfully submitted then go to next page (subject.php) $_SESSION['category'] = $_POST['category']; $url = BASE_URI . 'subject.php'; // Define the URL: header("Location: $url"); exit(); // Quit the script. My problem is when I need to go to category.php page from subject.php page clicking on browser's back button its not going and not loading the page. I tried using GET method instead of POST then working but always I cant use GET method. Can I know is there a solution with POST method? Thank you. Quote Link to comment https://forums.phpfreaks.com/topic/273357-how-i-prevent-from-this-problem/#findComment-1407627 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.