SitePoint Sponsor

User Tag List

Results 1 to 11 of 11

Thread: How to avoid...

  1. #1
    SitePoint Zealot daemon's Avatar
    Join Date
    Apr 2001
    Posts
    100
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I coded a page in php.
    But when hitting the browzers back button you get the following:

    "Data Missing

    This document resulted from a POST operation and has expired from the cache. If you wish you can repost the form data to recreate the document by pressing the
    reload button. "

    This is completely undesireable.
    How can i fix this?
    I know what this means but i don't know why exactely i get it.
    The page i'm trying to do looks something like this:

    if($action=="index") {
    do some stuff
    }
    if($action=="billing") {
    do some other stuff
    }

    then the action value gets cahnged and the page reloaded (throug links using $PHP_SELF)

    Pleas help.

  2. #2
    ********* Callithumpian silver trophy freakysid's Avatar
    Join Date
    Jun 2000
    Location
    Sydney, Australia
    Posts
    3,798
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    which browser are you using?

  3. #3
    SitePoint Zealot daemon's Avatar
    Join Date
    Apr 2001
    Posts
    100
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Netscape (under linux).
    But it's all the same using IE5 under Win32.

  4. #4
    SitePoint Zealot daemon's Avatar
    Join Date
    Apr 2001
    Posts
    100
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    As I just figured out this is in somehow corelated to the
    call of some session_start and session_register functions.

    Hope this helps.

  5. #5
    SitePoint Zealot daemon's Avatar
    Join Date
    Apr 2001
    Posts
    100
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    ehm, my last reply sounds a bit like this is soved
    but it is NOT!!

    Any help is really appreciated!!!

  6. #6
    Grumpy Mole Man Skunk's Avatar
    Join Date
    Jan 2001
    Location
    Lawrence, Kansas
    Posts
    2,066
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    It sounds like the page you are going 'back' to has been created as the result of a form being "Posted" - i.e to get to the page you click a submit button which submits data to that page / script via POST.

    The simplest fix would be to change this to use GET instead - alter the HTML for the form that creates the page and ensure the method attribute looks like this:

    <form action="whatever-it-was" method="get">

  7. #7
    SitePoint Enthusiast
    Join Date
    Feb 2001
    Location
    Monmouth Junction, NJ
    Posts
    88
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    yes changing POST to GET should most probably result in that undesired page to appear requesting a reload

  8. #8
    SitePoint Zealot daemon's Avatar
    Join Date
    Apr 2001
    Posts
    100
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    GET is no option cause it's a password

    Here goes the code of the page:

    PHP Code:
    <?php
            
    include("accesscontrol.php");   //if no session is started let the user type his password
                                            //this is manely taken from Kevin Yank's PHP session tutorial
            
    include("header.inc");          //simple HTML header

            
    if($action=="index" OR $action=="") {
                    
    //-----Main Index goes here------------------
                    
    ?>
                    <a href="change.php">Change user data</a><p>
                    <a href="<?php echo($PHP_SELF "?action=change"); ?>">Change user data</a><p>
                    <a href="<?php echo($PHP_SELF "?action=bill"); ?>">Rechnung</a><p>
                    <a href="<?php echo($PHP_SELF "?action=other"); ?>">other</a><p>
                    <a href="<?php echo($PHP_SELF "?action=logout"); ?>">Logout</a><p>
                    <?php
                    
    include("footer.inc");  //simple HTML footer
            
    //endif index

            
    if($action=="bill") {
                    
    //here goes our billing stuff
                    
    $action="index";
                    echo(
    "billing\n\r hallo?");
                    echo(
    $uid);
                    echo(
    $password);
            } 
    //endif bill

            
    if($action=="change") {
                    
    //here goes our change stuff
                    
    echo("change\n");
                    echo(
    $plate);
            include(
    "footer.inc");
            } 
    //endif change

            
    if($action=="logout") {
                    
    session_destroy();
                    echo(
    "Logged out\n");
                    include(
    "footer.inc");
                    exit;
            } 
    //endif logout
    ?>
    All this should do is load, if the user has successfully identified, a main index.
    Here the user can choose several options that are displayed using the value from $action.
    This works fine till viewing the billing page for instance.
    But when you hit back (after viewing the billing page!!!) I get this error.

    Any idea how to fix it OR to write it in another way would be great.

    Thanks anyway.

  9. #9
    One website at a time mmj's Avatar
    Join Date
    Feb 2001
    Location
    Melbourne Australia
    Posts
    6,282
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    So when the user goes back, what would you like to happen?

    a: The page is invalid, and cannot be reloaded
    b: The page is reloaded automatically without needing to POST the data again.

    if a: You cannot really do this without a bit of a redesign. You'd have to make the session "invalid" (by adding a session variable) so that after going back to that page and reposting the data, the script realises the session is now "invalid" and displays an error message instead of working on the data.

    if b: You would do this by adding a "validator" to the outgoing http response header for that page. Then, the browser would reload it from the cache, without the data 'expiring'.

    PHP Code:
    header("Cache-Control: private, max-age=86400");
    header("Expires: Expires: ".gmdate("D, d M Y H:i:s"time() + 86400)." GMT");
    //86400 makes the page valid for one day.
    //private means that the page is specific to one person, and
    //  shouldn't be cached by public proxy caches 
    [mmj] My magic jigsaw
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    The Bit Depth Blog Twitter Contact me
    Neon Javascript Framework Jokes Android stuff

  10. #10
    Don't eat yellow snow spaceman's Avatar
    Join Date
    Mar 2001
    Location
    Melbourne, Australia
    Posts
    1,039
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Same issue, different forum, same answer (but still worth a read):

    http://forums.devshed.com/showthread...3537&forumid=3

  11. #11
    SitePoint Zealot daemon's Avatar
    Join Date
    Apr 2001
    Posts
    100
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hey I solved it!!
    The problem is not to not-cache the data, on the contrary: cache it!!!
    I simply inserted a:
    header("Pragma: cache");
    and it worked.
    Another possiblity I just got from Kevin Yanks is to blindly
    reload the page a second time right after the login. Here's
    his code:
    PHP Code:
            if ($action=="") { // No action set. The user may have just logged in.
              
    header("Location: ${PHP_SELF}?action=index");
              exit;
            } 
    The third thing that came to my mind was to simply place a
    "click here to go back" link on the page. But this doesn't actually solve the problem, it's more a "workaround".

    Thanks for all your ideas and helpfull advices.


Bookmarks

Posting Permissions

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