How know if the php page was reached by a posted form?

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
6tr6tr
Forum Newbie
Posts: 4
Joined: Mon Jun 08, 2009 4:50 pm

How know if the php page was reached by a posted form?

Post by 6tr6tr »

How can i tell if a POST method is what reached the php page? I tried the code below, but it is always true:

Code: Select all

if ( isset( $HTTP_POST_VARS ) )
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: How know if the php page was reached by a posted form?

Post by requinix »

Stop using $HTTP_POST_VARS and start using $_POST.

Hint: look in $_SERVER.
User avatar
mikemike
Forum Contributor
Posts: 355
Joined: Sun May 24, 2009 5:37 pm
Location: Chester, UK

Re: How know if the php page was reached by a posted form?

Post by mikemike »

Code: Select all

if(!empty($_POST))
works for me
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: How know if the php page was reached by a posted form?

Post by requinix »

mikemike wrote:

Code: Select all

if(!empty($_POST))
works for me
But what if there wasn't anything posted?
Torrodon
Forum Newbie
Posts: 4
Joined: Sun Jun 07, 2009 7:24 am

Re: How know if the php page was reached by a posted form?

Post by Torrodon »

Better check if the variable you are going to use are what they should be

Code: Select all

if($_POST[submit_button_name] <> 'Submit') .....             //this include empty var
6tr6tr
Forum Newbie
Posts: 4
Joined: Mon Jun 08, 2009 4:50 pm

Re: How know if the php page was reached by a posted form?

Post by 6tr6tr »

mikemike wrote:

Code: Select all

if(!empty($_POST))
works for me
Thanks that one works.

Just out of curiousity, why is _POST better than the previous HTTP_POST_VARS?
User avatar
jayshields
DevNet Resident
Posts: 1912
Joined: Mon Aug 22, 2005 12:11 pm
Location: Leeds/Manchester, England

Re: How know if the php page was reached by a posted form?

Post by jayshields »

$HTTP_POST_VARS is deprecated, and it isn't a superglobal.
Post Reply