Re: Re: Best way to test for form submission?
| From: | Ashley Sheridan | Date: | Fri, 28 Aug 2009 16:51:38 +0000 |
| Subject: | Re: Re: Best way to test for form submission? | ||
| References: | 1 2 3 4 5 6 7 8 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-297434@lists.php.net to get a copy of this message | ||
On Fri, 2009-08-28 at 09:33 -0700, Ben Dunlap wrote:
> I was surprised when no one recommended this:
>
> if ($_SERVER['REQUEST_METHOD'] == 'POST')
>
> So now I'm wondering if there's a pitfall to this method that I'm not
> aware of...
>
> Thanks,
>
> Ben
>
Well, as far as I'm aware $_SERVER isn't reliable from server to server.
That said, I've never had a problem using it.
I probably wouldn't use this however, as it does only check for the
existence of POST data. Sometimes I'll trigger the same PHP script from
both POST and GET. For example, a search form would use POST in the
initial form, and then if it was paginated, the links forwards and
backwards through the results would be GET (like Google) I usually just
tend to use the $_REQUEST array instead of $_POST or $_GET. You get the
benefit of being able to work with both arrays (as well as $_SESSION and
$_COOKIE) without any drawbacks.
Thanks,
Ash
http://www.ashleysheridan.co.uk