I can't seem to get anything to work with IE9. I have a page that has a form. Once the form is submitted, the user is redirected to a "Wait, processing" page that redirects to the final page after a few seconds. I want the "Wait, processing" page to be skipped if the user clicks on the back button in their browser. I've tried all of the different meta tags and Cache-Control's such as header("Cache-Control: private, no-cache, no-store"); but nothing works for IE9. Is there anyway to accomplish this?
Also why not have the form information saved to a temporary .txt file in case they do have to back-track you can use history, but if their browser closes, something else occurs. When they submit form it will go to your wait page (why a wait page though?) it would send info to your database (assumable) and will also store the info to a fwrite() text file thats created from their IP to make it unique. newuser_$ip.txt It's also useful if your ecommerce requires people to have a membership but allows them to shop FIRST before signing up. It will store the text file until its successful entered to database then any text file in the NEWUSERS folder matching that IP is deleted. You can use the same IP system and text filewrite to track the time they spend on each page. Also asking simple questions on each page that allows a user to earn reward points or savings on your products. (example question: "Do you have a business? yes - no) Next page, "How many of these products do you purchase a year?" Its a simple way to ask questions one per page,without bombarding them yet it compiles in a text file and builds a customer /visitor profile that's then stored to database.
Great info but neither recommendation will work in my case. Sorry, I did not provide enough information. The wait page is more than just a wait page. It sometimes holds info from the form page, then it uses GET to pass the info to a 3rd page. Here's the kicker... The 3rd page is not a set page. It can be any page and sometimes it's a public page that I do not have access to. When using the back button in FireFox, the 2nd page is skipped when I add header("Cache-Control: private, no-cache, no-store"); to the 2nd page. That's why I was hoping PHP or JavaScript code could be used to set a header or do whatever is necessary to keep the 2nd page out of browser history.
Firefox and IE work differently, which is why you can't get them to work the same way. What you can do is take advantage of one of the problems with AJAX - don't use a separate page for the "wait" - use AJAX to put the "wait" information on the page that's doing the submit. Then when you redirect from that page, any browser's back button will go back to the page "before" the "wait". (Manipulating the browser's history is doable, but a) a knowledgeable user will never visit your site again and b) you need different code for just about every browser, and you may need to change it for future versions of the same browser. It's one of those things that's very heavily frowned upon.)
Rukbat, thanks for the info on Ajax but I have to have a separate page for the "wait". After more googling, I'm thinking sessions or maybe cookies may be the only way for me to accomplish my task without starting all over. I think if I find a good example that's really close to what I want to do, I can then tweak the example so it works for me. Right now, I'm just not sure what code goes on which page. Here's basically what I'm dealing with: Page1 is an HTML form which POSTs some data to Page2 which is a php script. Page2 checks the data and if the data is not correct it redirects to Page1. If the data is correct, Page2 POSTs some other data to Page3 which is the wait page. Page3 checks the data. Page3 then redirects to Page4 which is the final destination. If a user clicks on their browser's back button while on Page4, I want them directed back to Page1. Currently, users get Page3 when they hit the back button and then Page1 if they hit the back button again. I think I got it. Can someone please tell me if my code is OK or how I can improve it? Page1 <form name="1" method="post" action="2.php"> <input type="hidden" name="entered" value="1" /> <input type="submit" name="submit" value="Enter" /> </form> HTML: Page2 <?php if(isset($_POST['entered'])) { // Check to see promo code submitted from 'promocode/html/securedExpiredErrorPage.php' $entered = 1; session_start(); $_SESSION[entered] = 1; session_write_close(); } header("location: 3.php"); ?> PHP: Page3 <?php session_start(); if(isset($_SESSION["entered"])){ echo "Came from Page1.<br/><br/>\$_SESSION[\"entered\"] = ".$_SESSION["entered"]."<br/><br/>"; echo "Redirecting to Page4..."; session_destroy(); header('refresh: 4; url=4.php'); exit(); }else{ //echo "Did not come from Page1"; session_destroy(); header("location: 1.php"); exit(); } ?> PHP: Page4 Page4 HTML:
The code in my previous post seems to works but can someone please tell me why adding another variable does not? If I change Page3 to the following: <?php session_start(); if(isset($_POST['entered'])) { // Check to see promo code submitted from 'promocode/html/securedExpiredErrorPage.php' $_SESSION[entered] = $_POST['entered']; } if(isset($_POST['page'])) { // Check to see promo code submitted from 'promocode/html/securedExpiredErrorPage.php' $_SESSION['page'] = $_POST['page']; } session_write_close(); header("location: 3.php"); ?> PHP: The value of the 'page' variable is not saved in the session. Below is the content of the session file: entered|s:1:"1";page|N; Code (markup):
$_SESSION[page] is never being set, so it's not being saved. Why? There's nothing you can do on a page that you can't do with AJAX. About the only legitimate reason for having to have an additional page is that this is a school assignment, and that's part of the assignment.
I triple checked everything and it is being POST'ed so I'm not sure what the problem is. I know what AJAX is but I have zero experience with it. Presumably, you are talking about adding AJAX to Page4 instead of using a "wait" page in the middle. Here's my problem with that... The final page (Page4) is not always the same page and sometimes it's a public page so i will not beable to add AJAX to it. That's why I say I need the "wait" page which does some verification and then redirects to Page4. Is my assumption correct?
Where? Not in the code you showed us. No, to page 2 I think - the page before your wait page. The Javascript (that's what AJAX is in the client) displays the "Please wait" and determines which "page 4" to redirect to - exactly what your (page 3, is it? the wait page) does. You can have the PHP that page 2 talks to determine the correct page 4, if that's where that code is, then send the decision back to page 2 as one of the returned variables. Or the Javascript in page 2 can do it. (I don't know what the "which page 4" decision is based on.) No. See above.
I edited the code in Page1. I just didn't add the revised snippet to my previous post. I'll look into using AJAX but that's going to be nearly a complete code overhaul and I have no idea how or where to add the AJAX. Can you please add AJAX to my simple example in post #6 so I can better understand how it works? I guess adding a couple of verification steps to Page2 would be necessary. Something like if the text entered in Page1 is too short, show an AJAX alert and then redirect back to Page1. I'll keep searching for examples as well. Thanks, Jeff
Just delete one line in page2 and add whatever Javascript you need, then add one PHP page. Instead of line 8 in Page2. Something like: <?php if(isset($_POST['entered'])) { // Check to see promo code submitted from 'promocode/html/securedExpiredErrorPage.php' $entered = 1; session_start(); $_SESSION[entered] = 1; session_write_close(); } //header("location: 3.php"); whatever(); function GetXmlHttpObject() { var xmlHttp=null; try { // Firefox, Opera 8.0+, Safari xmlHttp=new XMLHttpRequest(); } catch (e) { // Internet Explorer try { xmlHttp=new ActiveXObject("Msxml2.XMLHTTP"); } catch (e) { xmlHttp=new ActiveXObject("Microsoft.XMLHTTP"); } } return xmlHttp; } function whatever() { xmlHttp=GetXmlHttpObject(); if (xmlHttp==null) { alert ("Your browser does not support AJAX!\n\nDownload Firefox."); return false; } var url="page3.php"; url=url+"?data=whatever page3 needs to do whatever it does"; xmlHttp.onreadystatechange=callback; xmlHttp.open("GET",url,true); xmlHttp.send(null); return false; } function callback() { if (xmlHttp.readyState==4) { if (xmlHttp.status == 200) { //xmlHttp.responseText; //this is the output of page3.php //do what you need with it here //you can display it or do a redirect with //window.location = "http://" + some_variable_you_parse_out_of_xmlHttp.responseText; } else { //if there's an error, say something in some div document.getElementById('display').innerHTML = 'An error (' + xmlHttp.status + ') occurred: ' + xmlHttp.statusText; } } } PHP: If the text is too short, Javascript can detect it without AJAX.
Thanks Rukbat!. I appreciate you taking the time to give the example. Haven't gotten Ajax to work quite right but I'm still playing around with it.