• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 387
  • Last Modified:

Page has Expired

Dear Experts

When I use post to process the form, if I click back button of the browser, browser gives me "Page has Expired" error and it asks me to refresh the page. I don't want to use get method. What would be the other ways to do it without getting that error?

Kind regards
0
hasozduru
Asked:
hasozduru
  • 3
  • 3
  • 2
  • +2
3 Solutions
 
arantiusCommented:
There's only one thing you can do.  POST to one page to perform the action, and have it Location: header to another page that displays the results.
0
 
hasozduruAuthor Commented:
You mean all the professional web sites doing in this way?
0
 
arantiusCommented:
I can't say for sure.  That's how I do it, and I don't believe there's a better way to acheive that particular effect.
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
ldbkuttyCommented:
Thats the way I also do. This avoids repeatition of the page function. For example, consider a page insert_employee.php that inserts an employee record to the database. If the page is NOT redirected to another page after inserting the record, "Refreshing" a page might result in duplicate record!

This is my approach:

insert_employee.php
=============

<?php
session_start();
if(isset($_POST['insert_employee_form']) && !empty($_POST['insert_employee_form']))
{
    // Insert the record into the database here..
   $_SESSION['auth_page'] = basename($_SERVER['PHP_SELF']);
   session_write_close();
   header("Location: next_page.php?rc_inserted=true");
   exit();
}
?>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="POST">
...
...
<input type="submit" name="insert_employee_form" value="Submit"/>
</form>

and in next_page.php
===============

<?php
session_start();

// If this page is called from insert_employee page.
if(isset($_SESSION['auth_page']) && $_SESSION['auth_page'] == 'insert_employee.php')
{
    if(isset($_GET['rc_inserted']) && $_GET['rc_inserted'] == 'true')
    {
        echo 'Record inserted!';
    }
}

// Change the session variable to avoid displaying 'Record inserted' again if this page is refreshed!
$_SESSION['auth_page'] = basename($_SEVER['PHP_SELF']);

/* Your stuff here */
?>
0
 
hasozduruAuthor Commented:
I am trying a different method like following but it doesn't work. It says Fatal error: Call to undefined function: tep_draw_form() What can be the reason? Will it say Page has Expired if I use this code?

Thanks


function tep_draw_form($action, $method) {
    //$form = '<form action="' . ($action) . '" method="' . ($method) . '">';
    $form = '<form action=' . $action . '" method="' . $method . '">';

   
    return $form;
  }

echo tep_draw_form('baskets2.php','post');

0
 
ldbkuttyCommented:
Is the function in the same page ? Do you get Fatal error always or only if back button is pressed?

you miss a double-quote in the form action. It could also be written as:

<?php
function tep_draw_form($action, $method) {
    $form = "<form action='$action' method='$method'>";  
    return $form;
}
echo tep_draw_form('baskets2.php', 'post');
?>
0
 
hasozduruAuthor Commented:
Yes the function is in the same page. I get Fatal error when I load the page (without pressing back button). I changed it to your code but it still giving same error.
0
 
ldbkuttyCommented:
what is the output of:

<?php
function tep_draw_form($action, $method) {
    $form = "<form action='$action' method='$method'>";  
    return $form;
}
$my_functions = get_defined_functions();
print_r($my_functions['user']);
?>
0
 
_Marcel_Commented:
Depending on your wishes there is another way. You cannot use location.replace() in javascript, since this will only allow you to submit GET-requests, but you can sent back an empty page after your php. This can be done with:

header("HTTP/1.0 204 No Content");

Take a look at http://www.sitepoint.com/article/no-refresh-links also. Another, even dirtier way to go is submitting the form to a non-showing IFRAME (for example in a non-showing DIV), and send only javascript as result. In that way you can alter the form, send messages, and also sent a redirect, or location.replace statement. The only reason to do this in this way is to obfuscate or even by-pass the history-object of your browser (making sure that posts are not getting into the history-object).

But remember: this can easily be a very dirty way to do it...
0
 
Andy_NeodyniumCommented:
The same problem is answered in Java at : http://www.javaworld.com/javaworld/jw-09-2004/jw-0927-logout.html

It deals mainly with Log out as it is using Sessions to track a user. However, you'll still get the question about resubmitting post data: this is a feature of the client.

Ldbkutty's answer is probably the most straight forward approach
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 3
  • 3
  • 2
  • +2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now