Jump to content
Larry Ullman's Book Forums

Confusing: Request, Get Or Post?


Recommended Posts

Hello,

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?

Link to comment
Share on other sites

$_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?

  • Upvote 2
Link to comment
Share on other sites

 Share

×
×
  • Create New...