| Start |
|---|
| Reading raw POST data Usually data sent in a POST request is structured key/value pairs with a MIME type of
This variable has been deprecated since PHP version 5.6, and was removed in PHP 7.0. Note that neither of these methods are available when the content type is set to |
| Reading POST data Data from a POST request is stored in the superglobal (opens new window) Note that accessing a non-existent array item generates a notice, so existence should always be checked with the Example: |
| Reading GET data Data from a GET request is stored in the superglobal (opens new window) Note that accessing a non-existent array item generates a notice, so existence should always be checked with the Example: (for URL |
| Handling file upload errors The
An basic way to check for the errors, is as follows: |
| Uploading files with HTTP PUT PHP provides support (opens new window) for the HTTP PUT method used by some clients to store files on a server. PUT requests are much simpler than a file upload using POST requests and they look something like this: Into your PHP code you would then do something like this: Also here (opens new window) you can read interesting SO question/answers about receiving file via HTTP PUT. |
| Passing arrays by POST Usually, an HTML form element submitted to PHP results in a single value. For example: This results in the following output: However, there may be cases where you want to pass an array of values. This can be done by adding a PHP-like suffix to the name of the HTML elements: This results in the following output: You can also specify the array indices, as either numbers or strings: Which returns this output: This technique can be used to avoid post-processing loops over the RemarksChoosing between GET and POSTGET requests, are best for providing data that's needed to render the page and may be used multiple times (search queries, data filters...). They are a part of the URL, meaning that they can be bookmarked and are often reused. POST requests on the other hand, are meant for submitting data to the server just once (contact forms, login forms...). Unlike GET, which only accepts ASCII, POST requests also allow binary data, including file uploads (opens new window). You can find a more detailed explanation of their differences here (opens new window). Request Data VulnerabilitiesAlso look at: what are the vulnerabilities in direct use of GET and POST? (opens new window) Retrieving data from the $_GET and $_POST superglobals without any validation is considered bad practice, and opens up methods for users to potentially access or compromise data through code (opens new window) and or SQL injections (opens new window). Invalid data should be checked for and rejected as to prevent such attacks. Request data should be escaped depending on how it is being used in code, as noted here (opens new window) and here (opens new window). A few different escape functions for common data use cases can be found in this answer (opens new window). |
Read Article
https://develop.horje.com/learn/1434/reference