Problem when reloading PHP page

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
arzoo
Forum Newbie
Posts: 3
Joined: Fri Sep 11, 2009 3:47 am

Problem when reloading PHP page

Post by arzoo »

I noticed something bothersome when I have a page that whose text fields are are filled data retrieved from POST. This is fine, but when the user suddenly opts to press <enter> in the address bar, the page reloads but this time without the posted data, so kinda messing things up. If the user reloads the page with the refresh button things are ok. This is in firefox.

Here's a simple example to illustrate. This is the form portion of a page that will POST to test.php:

Code: Select all

<form action="test.php" method="post">
Name: <input type="text" name="fname" />
Age: <input type="text" name="age" />
<input type="submit" />
</form>
Then here's test.php which retrieves the POST and prints them.

Code: Select all

Welcome <?php echo $_POST["fname"]; ?>!<br />
You are <?php echo $_POST["age"]; ?> years old.
All works fine. But after test.php loads properly, if the user chooses to press <enter> on the address bar which has http:localhost/.... test.php, it reloads test.php but this time without the POSTed data.
oscardog
Forum Contributor
Posts: 245
Joined: Thu Oct 23, 2008 4:43 pm

Re: Problem when reloading PHP page

Post by oscardog »

That is exactly what should happen and will happen, and unless you store the data in a session or something (which I wouldn't recommend as the chances are if a person is doing that they don't want their data).

When you do what you described it essentially just creates a fresh page, as it would look for the first load.
Post Reply