$_GET vs $_POST?
Users often ask what are the differences between the
$_POST variables in PHP and GET and POST HTTP methods in general.
First some background on the HTTP methods. GET and POST are two of many HTTP methods (GET, HEAD, POST, PUT, DELETE, TRACE, OPTIONS, CONNECT and PATCH) used to indicate the desired action to be performed on the identified resourse.
Query strings are sent in the URL of the GET request:
You can than get the query strings in PHP like this:
<?php $name1 = filter_has_var(INPUT_GET, 'name1') ? filter_input(INPUT_GET, 'name1', FILTER_SANITIZE_STRING) : false;
In case of POST method query strings are sent in the HTTP message body of the POST request:
POST /test/form.php HTTP/1.1 Host: test.com name1=value1&name2=value2&name3=value3
Query strings from POST method can be than processed in PHP like this:
<?php $name1 = filter_has_var(INPUT_POST, 'name1') ? filter_input(INPUT_POST, 'name1', FILTER_SANITIZE_STRING) : false;
Content of this work is licensed under a Creative Commons Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license. Code snippets in examples are published under the CC0 1.0 Universal (CC0 1.0). Thanks to all the contributors.