how to handle missing $_POST parameters

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
davidklonski
Forum Contributor
Posts: 128
Joined: Mon Mar 22, 2004 4:55 pm

how to handle missing $_POST parameters

Post by davidklonski »

Hello

I have a page called 'test.php'

The page contains a form with method POST
here is the definition:
<form method="post" action="test.php">

As you see, the user submits the form to the same page the form was defined at.

Now, whenever I surf to that page directly, I get the following error message in the browser:

"The page cannot be refreshed without resending the information. Click Retry to send the information again, or click Cancel to return to the page that you were trying to view."

If I click Retry then everything is ok.

How can I detect in PHP that no information has been sent?

thanks in advance
User avatar
patrikG
DevNet Master
Posts: 4235
Joined: Thu Aug 15, 2002 5:53 am
Location: Sussex, UK

Post by patrikG »

use

Code: Select all

header("cache: private");
at the top of the page.
Steveo31
Forum Contributor
Posts: 416
Joined: Sun Nov 23, 2003 9:05 pm
Location: San Jose CA

Post by Steveo31 »

Just curious, is there any difference in using the same name as the page, as opposed to $_SERVER['PHP_SELF']; ?
User avatar
patrikG
DevNet Master
Posts: 4235
Joined: Thu Aug 15, 2002 5:53 am
Location: Sussex, UK

Post by patrikG »

$_SERVER['PHP_SELF'] returns the name of the "page" that either calls or contains the php-script.
Post Reply