Jump to content


Confusing: Request, Get Or Post?

  • Please log in to reply
2 replies to this topic

#1 Roxana



  • Members
  • Pip
  • 17 posts

Posted 23 July 2012 - 6:04 AM

Could somebody please give me an example when to use each one of these?
My data is sent to a php file which updates a database.
Which method is safest? Why?
Why do the other methods even exist?
I read that if data was sent with post/get it should be retrieved with post/get.
Then how should it be sent to be retrieved with request?
  • 0

#2 HartleySan


    Advanced Member

  • Members
  • PipPipPip
  • 3042 posts
  • LocationColumbus, OH USA

Posted 23 July 2012 - 7:15 AM

$_REQUEST actually contains the contents of $_GET or $_POST, depending on the method used.
However, because I prefer to be more precise in my coding, I never use it. I always use $_GET or $_POST instead.
One important thing to note is that PHP does not choose which method to use. Instead, the one that is available depends on how a request is sent to the PHP script from another script (e.g., the request method used for an HTML form, a hyperlink on the page, etc.).

$_GET should be used for requests that are simply requesting information (for viewing), but not actually modifying anything; think SELECT SQL statements.
$_POST should be used for requests that will modify something; think UPDATE and INSERT SQL statements.

The biggest difference between the two is that $_GET requests display all the information being sent to the PHP script in the URL for anyone to see. $_POST information is never displayed in the URL, and also, you can send a lot more info via the post method than the get method. The post method is generally considered more secure.

If you're modifying a DB or sending some personal information that no one should see, use the post method. If the information isn't that secretive, and you want to make the results page bookmark-able, use the get method.
Probably the most common use of the get method is for search results pages. Check out the search results pages of Amazon, Google, etc. to see what I mean. In almost all other cases, you'll probably want to use the post method.

That answer your questions?
  • 2

#3 Roxana



  • Members
  • Pip
  • 17 posts

Posted 23 July 2012 - 9:22 AM

  • 0