Difference Between Get and Post Method in PHP ?
| $_GET Method | $_POST Method |
|---|---|
| GET requests can be cached. | POST requests are never cached. |
| GET requests remain in the browser history. | POST requests do not remain in the browser history. |
| Easier to hack for script kiddies. | More difficult to hack. |
| Restrictions on form data type. Only ASCII characters allowed. |
No restrictions. Binary data is also allowed. |
| GET requests can be bookmarked. | POST requests cannot be bookmarked. |
| GET is less secure compared to POST because data sent is part of the URL. So it’s saved in browser history and server logs in plaintext. |
POST is a little safer than GET because the parameters are not stored in browser history or in web server logs. |
| GET requests have length limitations. | POST requests have no limitations on data length . |
| GET method should not be used when sending passwords or other sensitive data. GET requests is only used to request data (not modify). |
POST method used when sending passwords or other sensitive data. |
Sample Code[pastacode lang=”markup” manual=”%3C!DOCTYPE%20html%3E%20%0A%3Chtml%20lang%3D%22en%22%3E%20%0A%3Chead%3E%0A%20%3Ctitle%3EExample%20of%20PHP%20GET%20method%3C%2Ftitle%3E%20%0A%3C%2Fhead%3E%20%0A%3Cbody%3E%20%0A%3C%3Fphp%0A%20if(isset(%24_GET%5B%22name%22%5D))%7B%0A%20echo%20%22%3Cp%3EHi%2C%20%22%20.%20%24_GET%5B%22name%22%5D%20.%20%22%3C%2Fp%3E%22%3B%20%0A%7D%20%3F%3E%0A%20%3Cform%20method%3D%22get%22%20action%3D%22%3C%3F%0Aphp%20echo%20%24_SERVER%5B%22PHP_SELF%22%5D%3B%3F%3E%22%3E%0A%20%3Clabel%20for%3D%22inputName%22%3EName%3A%3C%2Flabel%3E%20%0A%3Cinput%20type%3D%22text%22%20name%3D%22name%22%20id%3D%22inputName%22%3E%0A%20%3Cinput%20type%3D%22submit%22%20value%3D%22Submit%22%3E%20%0A%3C%2Fform%3E%20%0A%3C%2Fbody%3E” message=”” highlight=”” provider=”manual”/] |
Sample Code |
