Enter your email id to get regular update free
Login
Your Email
Pasword

Learn PHP GET-POST Method

PHP is a popular general-purpose scripting language that is especially used for web site development. PHP script is usually processed on a web server. Rasmus Lerdorf developed the first version of PHP in the year 1994.

PHP: 
  PHP is a popular general-purpose scripting language that is especially used for web site development. PHP script is usually processed on a web server. Rasmus Lerdorf developed the first version of PHP in the year 1994. PHP is integrated with a number of popular databases, Such as MySQL, PostgreSQL, Oracle, Sybase, Informix, and Microsoft SQL Server. 
   The main difference between PHP from client-side JavaScript is that the code is executed on the server, generating HTML information which is then sent to the client-side. The client would receive the results of running the PHP script, but would not know what the code of the PHP script was. 
   There are two ways the client browser can send information to the web-server. They are, 
1. The GET method 
2. The POST method 
Before the browser sends any information, it encodes it using a scheme called URL encoding. Spaces are removed and replaced with the + character and any other non-alphanumeric characters are replaced with a hexadecimal value. 
Syntax: 
                 name1=value1&name2=value2&name3=value3 
The GET Method:
   The GET method is used to sends the encoded client information appended to the page request. The page and the encoded information are separated by the “?” mark. 
Syntax: 
 http://www.testphp.com/index.htm?name1=value1&name2=value2 
Characteristics of GET method: 
1. The GET method in PHP produces a long string that appears in your server logs, in the browser's location. 
2. The GET method is restricted to send up to 1024 characters. 
3. Don’t use the GET method if a password or other sensitive information is to be sent to the server. 
4. GET method cannot be used to send binary data, like images or word documents. 
5. GET requests can be bookmarked by the user. 
6. For GET method PHP provides $_GET associative array to access all the sent information by the client to the server. 
7. GET requests can be cached by the user. 
Example: 
    When the user fills out the above form and clicks on the submit button, all the information or data from the form is sent for processing to a PHP. The form data is sent with the HTTP GET method. 
Output: 
Clicking on the “Submit” will produce the following result.
Here $_PHP_SELF variable contains the name of self script in which it is being called. 
The POST Method:
   The POST method is used to transfers information through the HTTP headers. The information sent by the client using the POST method is encoded and put into the HTTP header called QUERY_STRING. 
Characteristics of POST method: 
1. The POST method does not have any restrictions on data size, unlike the GET method. 
2. By using the POST method the client can send both ASCII as well as binary data. 
3. All the information or data sent by the POST method goes through HTTP header so security depends on the HTTP protocol. 
4. The PHP method provides $_POST associative array to access all the information sent using the POST method. 
 Example: 
When the user fills out the above form and clicks on the submit button, all the information or data from the form is sent for processing to a PHP. The form data is sent with the HTTP POST method. 
Output: 
Clicking on the “Submit” will produce the following result.
Here $_PHP_SELF variable contains the name of the self script in which it is being called. 
The $_REQUEST variable:
   The PHP $_REQUEST variable contains the contents of the variables $_GET, $_POST, and $_COOKIE. It can be used to get the result or information from the form that is sent using both the GET and POST methods. 
Difference between GET and POST method: 
GET methodPOST method
BACK button/ReloadHarmlessData or information will be re-submitted and the browser should alert the user about it.
BookmarkedCan be bookmarkedCannot be bookmarked
CachedCan be cachedCannot be cached
HistoryParameters remain in the browser historyParameters are not saved in the browser history
Restrictions on data lengthWhen sending data, the GET method adds the data to the URL; and the length of a URL is limited.No such restrictions
Restrictions on data typeOnly ASCII characters allowed to be sentNo such restrictions. Both binary data and ASCII characters are also allowed
SecurityGET method is less secure as compared to POST method because data sent is part of the URL. Never use GET method when sending passwords or other sensitive information / dataPOST method is a little safer as compared to GET method because the parameters are not stored in browser history or in web server logs.
VisibilityData is visible to everyone in the URLData is not displayed in the URL
Learn PHP GET-POST Method
GET-POST Method
Tutorial on GET-POST Method
Educational
Samiran Panda
Lecturer
Total 168 views