Is $_SERVER['REQUEST_METHOD'] still viable?
<p>So, for a while now I've been using the following to check if my post data has been set.</p>

<pre><code>if( ! empty( $_POST ) ) { }
</code></pre>

<p>But recently I've been seeing a lot of posts saying that the above is a "hack" and the below is the correct "better" way.</p>

<pre><code>if( $_SERVER[ 'REQUEST_METHOD' ] === 'POST' ) { }
</code></pre>

<p>By recently I just mean I've only recently found it. All the posts that are discussing this later method are from 2009'ish. A bit old by coding standards so I figure its ok to get a fresh opinion on this topic.</p>

<p>I've come to understand that the two methods are different. The first is considered a "hack" that just checks if the post array has been set, which will happen if a post request is made. The second actually checks the server to see if a post request has been made. I imagine the second might be a little more secure, but if the information is cleansed anyways I don't see how it makes much of a difference.</p>

<ul>
<li><a href="http://stackoverflow.com/questions/409351/post-vs-serverrequest-method-post">Source</a></li>
</ul>

<p>I've also seen posts that the later was only used in PHP versions &lt;= 4 because PHP was still using the <code>$_REQUEST</code> global at this point and this was the way PHP coders used to determine the source of certain request paramters. I'm not sure how accurate that last statement is, because the questions being posed in the older posts are the same as mine. They use the post global and not request. However, this is a more recent post than any of the others (2011), and from a source I've come to trust. So I'm not sure what to make of it.</p>

<ul>
<li><a href="http://forums.devshed.com/php-development-5/if-server-request-method-get-vs-if-isset-post-781746.html">Source</a></li>
</ul>

<p>And what to do when checking for get? I've seen a couple of places say that the server request method doesn't seem to work in this instance, and I can only assume that it is because post supercedes get and the request method can only hold one paramter. So if you have both post and get data what do you do? A comment on one of these posts suggests using the request global instead of post and get, but I've been under the impression that is a bad idea.</p>

<ul>
<li><a href="http://forums.devshed.com/php-development-5/if-server-request-method-get-vs-if-isset-post-781746.html">Source</a></li>
<li><a href="http://stackoverflow.com/questions/359047/php-detecting-request-type-get-post-put-or-delete">Source</a> In answer comments (nickf)</li>
</ul>

<p><a href="http://stackoverflow.com/questions/10943060/isset-postsubmit-vs-serverrequest-method-post">This</a> is the most recent source I could find, and I did so by looking through the similar questions on the side before submitting. It is specifically asking about using a submit value to check if the form was passed, but it does also mention the request method. A lot of it seems to indicate that the later is still being used commonly. So is this advice still valid? Is checking the request method still the best option?</p>
