Page 1 of 1

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

Posted: Mon Jun 08, 2009 4:51 pm
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 ) )

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

Posted: Mon Jun 08, 2009 6:35 pm
by requinix
Stop using $HTTP_POST_VARS and start using $_POST.

Hint: look in $_SERVER.

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

Posted: Mon Jun 08, 2009 7:29 pm
by mikemike

Code: Select all

if(!empty($_POST))
works for me

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

Posted: Mon Jun 08, 2009 8:15 pm
by requinix
mikemike wrote:

Code: Select all

if(!empty($_POST))
works for me
But what if there wasn't anything posted?

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

Posted: Mon Jun 08, 2009 9:13 pm
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

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

Posted: Tue Jun 09, 2009 8:50 am
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?

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

Posted: Tue Jun 09, 2009 8:53 am
by jayshields
$HTTP_POST_VARS is deprecated, and it isn't a superglobal.