Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8076543
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T15:16:53+00:00 2026-06-05T15:16:53+00:00

So, for a while now I’ve been using the following to check if my

  • 0

So, for a while now I’ve been using the following to check if my post data has been set.

if( ! empty( $_POST ) ) { }

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.

if( $_SERVER[ 'REQUEST_METHOD' ] === 'POST' ) { }

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.

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.

  • Source

I’ve also seen posts that the later was only used in PHP versions <= 4 because PHP was still using the $_REQUEST 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.

  • Source

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.

  • Source
  • Source In answer comments (nickf)

This 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?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T15:16:54+00:00Added an answer on June 5, 2026 at 3:16 pm

    Yes, it’s still there, and it’s still 100% reliable. The $_SERVER["REQUEST_METHOD"] var is set by PHP itself, based on the actual request method used by the user’s connection. A user can’t send in a query paramter or otherwise influence the value of that var, other than by changing the type of request.

    Your if(!$_POST) is not reliable, because it IS possible to perform a post but not send any data across it, e.g:

    <form method="post">
    <input type="submit" />
    </form>
    

    will produce just such an empty $_POST array – there are no named form elements in the form, so no data will be sent, yet a POST has still be performed.

    I would not worry about PHP4 not having this superglobal. PHP 4 is a stone age version, and code which supports v4 but built on v5 will have to contain so many ugly/disgusting hacks to achieve backwards compatibility that anyone having to work on that code would suffer from nightmares. PHP 4 should be considered dead and gone.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've been using IronPython for a while now, but something which really hampers my
I've been using Spring for a while now but I really don't know how
I've been using C# for a while now but haven't really homed in my
I've been using Vim for a while now and love it, but one thing
I've been wondering this for a while now; but especially more so since I've
I've been using ajax for a while now and I want to learn more
For while now I have been using ezpublish as a framework, and CMS when
For a while now, my team and I have been wrapping our data access
For a while now, I'm been using jQuery to offer enhancements via JavaScript on
I've been looking around quite a while now for an answer but since I'm

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.