Looking for solution to IE's "Webpage has expired" with SELF POST'd forms
Results 1 to 12 of 12

Thread: Looking for solution to IE's "Webpage has expired" with SELF POST'd forms

  1. #1
    PHP Addict dmacman1962's Avatar
    Join Date
    Aug 2003
    Location
    30,000 light years from center of Milky way in the orion arm.
    Posts
    619

    Looking for solution to IE's "Webpage has expired" with SELF POST'd forms

    Hi Everyone,

    I am 'hopefully' looking for a clean solution to IE's "Webpage has expired" issue when a user hits the 'Back' arrow in Internet Explorer when filling out a multi-page that I created (it is a ...
    Code:
    action="<?php echo $_SERVER['PHP_SELF'] ?>" method="POST" target="_self"
    action and is based on NogDogs solution posted here that works great, except of course, when the users moves on to page 2, and decides they want to go back (for reasons only they know) to page one and hit IE's back button.

    Then they get the "Webpage has expired" and are stuck unless they hit Refresh, which they may not think of (I found out on several occasions).

    I appreciate the help in advance as always,

    Don.

  2. #2
    Unfortunately, that message has to do with the way IE handles POST data. You can't change that, so you're out of luck unless you stop using POST variables.

    Here are your options, and reasons you should be careful about trying them:

    1. Switch your POST variables to GET
    - This is a bad solution for most forms, because GET variables are extremely limited in their content length, and they can also be edited or bookmarked by the user!

    2. Switch your form submission to AJAX
    - This requires solid knowledge of XHTML, PHP, and Javascript, and it adds a whole new dimension of complexity to writing cross-browser code.

    3. Put a message on the bottom of the page telling guests to be careful when pressing the back button, or telling them not to do it at all!

    4. Create your own "back" button, which will take them to the previous page of your form and automatically populate the form with the data they filled in previously.
    - You will probably need to use a session to do this.


    Hope that helped!
    If my post helped you, try my site:
    www.WeAnswer.IT

  3. #3
    Member
    Join Date
    Feb 2003
    Location
    Netherlands
    Posts
    57
    Depending on what you want to do with the POST data there is another solution. Let's say you want an email form, which ppl shouldn't be able to re-POST upon a page refresh when they cliked the back button.

    I'm not sure with the terminology but see it this way;

    The visitor requests form.php from the server (let's call this the passive page state)
    The visitor enters data and presses submit
    Now page form.php loads into the browser since you POST to PHP_SELF (let's call this the active page state, because it's loaded with POST data)
    When the vistor now refreshes or continues to another page and the clicks the back button he/she is going to hit the active page state again... and will get the page has expired message. So you want them actually to click back to the passive page state of form.php

    POST it to the page itself, at the beginning of the code you check if there is POST data, if so then process the data, and then do a header location to that very same page et voila! The active page state isn't returned to the browser but is being processed and the the visitor gets redirected to the passive page state again. They can click back or refresh the page all the want but the active page state never reached the browser so they can't refresh or click back to it!

    Hope it makes sense!
    I know not with what weapons World War III will be fought, but World War IV
    will be fought with sticks and stones.
    - Albert Einstein

  4. #4
    Hendricus, what you proposed makes sense but there is one problem. How does the "passive" page know when it needs to continue?

    The user will visit the passive page twice: once before filling out the form, and once after. The second time, the passive page needs to forward the user to a new page. How does it know how to do that?

    Not sure what you had in mind, or even if I understand your solution properly, but I immediately thought of using a GET variable. That's not possible, however, because then if the second visit to the passive page had a GET variable set on it (in order to tell it to redirect to the next page of the form), then clicking back in the browser would just redirect again.

    Example of your solution below:
    PHP Code:
    <?php

    if($_POST)
    {
        
    // form submitted; process the data
        // ... some processing code goes here ...

        // redirect to this page to make sure back button works
        
    header("Location: " $_SERVER['PHP_SELF'] . "?completed=true");
        exit;
    }
    else
    {
        
    // first visit to the passive page
        // but ALSO second visit
        // how do we know the difference?
    }

    ?>
    <form action="<?= $_SERVER['PHP_SELF'?>" method="post">
    </form>
    If my post helped you, try my site:
    www.WeAnswer.IT

  5. #5
    Member
    Join Date
    Feb 2003
    Location
    Netherlands
    Posts
    57
    Like I said, it depens on what you want to do with the POST-ed data! For an email form it would work nicely...

    What do you mean by "How does the "passive" page know when it needs to continue?" Continue onto what? Another page? Please explain a bit more what you want to do!

    Cheers
    I know not with what weapons World War III will be fought, but World War IV
    will be fought with sticks and stones.
    - Albert Einstein

  6. #6
    The whole time I was thinking he wanted to have another page of forms, and then if the user clicked back to edit the first page, they would get that error.

    Guess it depends on what he is using his forms for...
    If my post helped you, try my site:
    www.WeAnswer.IT

  7. #7
    Geek
    Join Date
    Jul 2007
    Posts
    780
    If it's not a ton of data, what i do sometimes is serialize the post info, load it into a session array, and redirect them back to the page.

  8. #8
    PHP Addict dmacman1962's Avatar
    Join Date
    Aug 2003
    Location
    30,000 light years from center of Milky way in the orion arm.
    Posts
    619
    Well, reading all the posts here, I am not sure what the final answer here is. (If I had my way, it would be a sign telling people "DONT use IE!" because in Firefox, this is a moot point.)

    Basically, this is a 2-part form, and here is the logic.

    PHP Code:
    if(isset($_POST['form1_submit']))
    {
       require 
    'form1_processor.php';  // process input from Form #1
       
    include("form1_errors.php");
       if(
    count($errors) == 0)  // no errors
       
    {
          require 
    'form2.php';  // displays Form #2
       
    }
       else
       {
        if(isset(
    $_POST['reset']))
        {
          
    $_SESSION = array();//initalize the array
          
    session_destroy();//reset was pressed, destroy all the session data
        

          require 
    'form1.php';  // re-displays Form #1
       
    }
    }
    elseif(isset(
    $_POST['form2_submit']))
    {
       require 
    'form2_processor.php';  // processes data from Form #2
       
    include("form2_errors.php");
       if(
    count($errors) == 0)
       {
           include(
    "vote.php");
        include(
    'success.php'); // all done
          
    exit;
       }
           else
           {
                 include(
    "form2_errors.php");
              require 
    'form2.php';  // re-display Form #2
           
    }
    }
        else
        {
            if(isset(
    $_POST['reset']))
            {
              
    $_SESSION = array();//initalize the array
              
    session_destroy();//reset was pressed, destroy all the session data
            

           require 
    'form1.php';  // display Form # 1
        

    And what I do on the forms, is I use SESSIONS to store the data, so if I need to re-display the page, the user data is stored so they do not have to fill it out again.

    Form 1 is the users basic data (name, address, grades they have taught (the 1st array of checkboxes) etc and what videos of ours they have used (the 2nd array of checkboxes).

    I use an errors function to test if they filled out all the required fields and to validate that they rated all the videos selected from Form1.

    Form 1 has the Rating radio buttons from Form 1 and the comments section.

    The issue (with IE only) is if they hit the Back button for any reason, it messes everything up.

    In Firefox, none of this is an issue at all. Everything works perfect.

    Does that make my it clearer or more clouded?

    Thanks for taking the time to help, and continued guidance,
    Don

  9. #9
    Member
    Join Date
    Feb 2003
    Location
    Netherlands
    Posts
    57
    Not a hundered percent sure now... but if I understand correctly you want one page to display different steps of a form then why not send a hidden POST value step=1 step=2 and store this in the session, then if(isset($_POST['form1_submit']) || $_SESSION['step'] == 1) { continue...

    Cheers
    I know not with what weapons World War III will be fought, but World War IV
    will be fought with sticks and stones.
    - Albert Einstein

  10. #10
    Junior Member
    Join Date
    Mar 2011
    Posts
    2

    My Simple Solution

    Ok, I know this thread is like a million years old, but in case anyone is still looking (like I was) here is my situation...I have a php page that posts to itself because of a form...so IE being it's WONDERFUL self kept giving me that wonderful "PAGE EXPIRED"...so I added:
    PHP Code:
    if(empty($_POST['search']))
        
    $search=mt_rnd();
    else
        
    $search=$_POST['search']; 
    At the top and added this to my form
    HTML Code:
    <form action="searchpage.php?search='.$search.'" method="post" name="search_ref_form" accept-charset="utf-8">
    Then at the bottom of my form I added:
    HTML Code:
    <input type="hidden" name="search" value="'.$search.'">
    This resolved my issue...I hope this helps someone int the future.

  11. #11
    Junior Member
    Join Date
    Mar 2011
    Posts
    2
    Also would just like to say to dmacman1962...I would not use "if (isset($_POST['var']))" (var being any key) as even an empty string will show as "set"...I would suggest you use "if (empty(($_POST['var']))" or "if (!empty(($_POST['var']))"...

  12. #12
    Junior Member
    Join Date
    Mar 2011
    Posts
    1

    page has expired problem

    Thanks for the great idea.
    I wonder how do you implement the solution in case of two files - the first is the form and the second presents the results?

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •