{"id":6166,"date":"2020-05-26T15:42:47","date_gmt":"2020-05-26T15:42:47","guid":{"rendered":"https:\/\/tutorialsclass.com\/?post_type=faq&#038;p=6166"},"modified":"2020-05-26T15:42:48","modified_gmt":"2020-05-26T15:42:48","slug":"difference-between-get-and-post-method-in-php","status":"publish","type":"faq","link":"https:\/\/tutorialsclass.com\/faq\/difference-between-get-and-post-method-in-php\/","title":{"rendered":"What is the difference between GET and POST method in PHP?"},"content":{"rendered":"\n<h3 class=\"wp-block-heading\">HTTP<\/h3>\n\n\n\n<p>The Hypertext Transfer Protocol (HTTP) is designed to enable communications between clients and servers.<\/p>\n\n\n\n<p>HTTP works as a request-response protocol between a client and server.<\/p>\n\n\n\n<p>A web browser may be the client, and an application on a computer that hosts a web site may be the server.<\/p>\n\n\n\n<p class=\"lang:php\">A client (browser) submits an HTTP request to the server; then the server returns a response to the client.<\/p>\n\n\n\n<p>A client (browser) submits an HTTP request to the server; then the server returns a response to the client. The response contains status information about the request and may also contain the requested content.<\/p>\n\n\n\n<p>There are two ways the browser client can send information to the web server.<br><code>GET <\/code>&#8211; Requests data from a specified resource<br><code>POST<\/code> &#8211; Submits data to be processed to a specified resource<\/p>\n\n\n\n<hr class=\"wp-block-separator\"\/>\n\n\n\n<h3 class=\"wp-block-heading\">GET Method<\/h3>\n\n\n\n<p>The GET method sends the encoded user information appended to the page request. The page and the encoded information are separated by the ? character.<\/p>\n\n\n\n<p>http:\/\/www.tutorialsclass.com\/index.htm?name1=value1&#038;name2=value2<\/p>\n\n\n\n<p>GET requests can be cached<br>GET requests remain in the browser history<br>GET requests can be bookmarked<br>GET requests should never be used when dealing with sensitive data<br>GET requests have length restrictions<br>GET requests should be used only to retrieve data<\/p>\n\n\n\n<pre class=\"wp-block-code language-php\"><code>&lt;!DOCTYPE html>\n&lt;html lang=\"en\">\n&lt;head>\n    &lt;title>Example of PHP GET method&lt;\/title>\n&lt;\/head>\n&lt;body>\n&lt;?php\nif(isset($_GET&#91;\"name\"])){\n    echo \"&lt;p>Hi, \" . $_GET&#91;\"name\"] . \"&lt;\/p>\";\n}\n?>\n&lt;form method=\"get\" action=\"&lt;?php echo $_SERVER&#91;\"PHP_SELF\"];?>\">\n    &lt;label for=\"inputName\">Name:&lt;\/label>\n    &lt;input type=\"text\" name=\"name\" id=\"inputName\">\n    &lt;input type=\"submit\" value=\"Submit\">\n&lt;\/form>\n&lt;\/body><\/code><\/pre>\n\n\n\n<hr class=\"wp-block-separator\"\/>\n\n\n\n<h3 class=\"wp-block-heading\">POST Method<\/h3>\n\n\n\n<p>The POST method transfers information via HTTP headers. The information is encoded as described in case of GET method and put into a header called <code>QUERY_STRING.<\/code><\/p>\n\n\n\n<p>The POST method does not have any restriction on data size to be sent.<\/p>\n\n\n\n<p>The POST method can be used to send ASCII as well as binary data.<\/p>\n\n\n\n<p>The data sent by POST method goes through HTTP header so security depends on HTTP protocol. By using Secure HTTP you can make sure that your information is secure.<\/p>\n\n\n\n<p>The PHP provides <code>$_POST<\/code> associative array to access all the sent information using POST method.<\/p>\n\n\n\n<pre class=\"wp-block-code language-php\"><code>&lt;!DOCTYPE html>\n&lt;html lang=\"en\">\n&lt;head>\n    &lt;title>Example of PHP POST method&lt;\/title>\n&lt;\/head>\n&lt;body>\n&lt;?php\nif(isset($_POST&#91;\"name\"])){\n    echo \"&lt;p>Hi, \" . $_POST&#91;\"name\"] . \"&lt;\/p>\";\n}\n?>\n&lt;form method=\"post\" action=\"&lt;?php echo $_SERVER&#91;\"PHP_SELF\"];?>\">\n    &lt;label for=\"inputName\">Name:&lt;\/label>\n    &lt;input type=\"text\" name=\"name\" id=\"inputName\">\n    &lt;input type=\"submit\" value=\"Submit\">\n&lt;\/form>\n&lt;\/body><\/code><\/pre>\n\n\n\n<hr class=\"wp-block-separator\"\/>\n\n\n\n<h3 class=\"wp-block-heading\">Advantages and Disadvantages of Using the GET Method<\/h3>\n\n\n\n<p>Since the data sent by the GET method are displayed in the URL, it is possible to bookmark the page with specific query string values.<br>The GET method is not suitable for passing sensitive information such as the username and password, because these are fully visible in the URL query string as well as potentially stored in the client browser&#8217;s memory as a visited page.<br>Because the GET method assigns data to a server environment variable, the length of the URL is limited. So, there is a limitation for the total data to be sent.<\/p>\n\n\n\n<hr class=\"wp-block-separator\"\/>\n\n\n\n<h3 class=\"wp-block-heading\">GET vs. POST<\/h3>\n\n\n\n<figure class=\"wp-block-table\"><table><tbody><tr><th><\/th><th>GET<\/th><th>POST<\/th><\/tr><tr><td>BACK button\/Reload<\/td><td>Harmless<\/td><td>Data will be re-submitted\n(the browser should alert the user that\nthe data are about to be re-submitted)<\/td><\/tr><tr><td>Bookmarked<\/td><td>Can be bookmarked<\/td><td>Cannot be bookmarked<\/td><\/tr><tr><td>Cached<\/td><td>Can be cached<\/td><td>Not cached<\/td><\/tr><tr><td>Encoding type<\/td><td>application\/x-www-form-urlencoded<\/td><td>application\/x-www-form-urlencoded or multipart\/form-data.\nUse multipart encoding for binary data<\/td><\/tr><tr><td>History<\/td><td>Parameters remain in browser history<\/td><td>Parameters are not saved in browser history<\/td><\/tr><tr><td>Restrictions on data length<\/td><td>Yes, when sending data,\nthe GET method adds the data to the URL;\nand the length of a URL is limited\n(maximum URL length is 2048 characters)<\/td><td>No restrictions<\/td><\/tr><tr><td>Restrictions on data type<\/td><td>Only ASCII characters allowed<\/td><td>No restrictions. Binary data is also allowed<\/td><\/tr><tr><td>Security<\/td><td>GET is less compared to\nPOST data sent is part of URL<\/td><td>POST is a little safer than GET because\nthe parameters are not stored\nin browser history or in web server logs<\/td><\/tr><tr><td>Visibility<\/td><td>Data is visible to everyone in the URL<\/td><td>Data is not displayed in the URL<\/td><\/tr><\/tbody><\/table><\/figure>\n","protected":false},"excerpt":{"rendered":"<p>HTTP The Hypertext Transfer Protocol (HTTP) is designed to enable communications between clients and servers. HTTP works as a request-response protocol between a client and server. A web browser may be the&#8230;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","template":"","meta":{"footnotes":""},"faq_type":[122],"keywords":[],"class_list":["post-6166","faq","type-faq","status-publish","hentry","faq_type-all-php-interview-questions-answers"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.1.1 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Difference between GET and POST Method in PHP - Tutorials Class<\/title>\n<meta name=\"description\" content=\"Difference between GET and POST Method in PHP - The POST method transfers data via HTTP headers and GET method into a header called QUERY_STRING\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/tutorialsclass.com\/faq\/difference-between-get-and-post-method-in-php\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Difference between GET and POST Method in PHP - Tutorials Class\" \/>\n<meta property=\"og:description\" content=\"Difference between GET and POST Method in PHP - The POST method transfers data via HTTP headers and GET method into a header called QUERY_STRING\" \/>\n<meta property=\"og:url\" content=\"https:\/\/tutorialsclass.com\/faq\/difference-between-get-and-post-method-in-php\/\" \/>\n<meta property=\"og:site_name\" content=\"Tutorials Class\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/tutorialsclass\" \/>\n<meta property=\"article:modified_time\" content=\"2020-05-26T15:42:48+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/tutorialsclass.com\/wp-content\/uploads\/2020\/07\/tutorials-class-logo.png\" \/>\n\t<meta property=\"og:image:width\" content=\"600\" \/>\n\t<meta property=\"og:image:height\" content=\"600\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:site\" content=\"@TutorialsClass\" \/>\n<meta name=\"twitter:label1\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data1\" content=\"3 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/tutorialsclass.com\/faq\/difference-between-get-and-post-method-in-php\/\",\"url\":\"https:\/\/tutorialsclass.com\/faq\/difference-between-get-and-post-method-in-php\/\",\"name\":\"Difference between GET and POST Method in PHP - Tutorials Class\",\"isPartOf\":{\"@id\":\"https:\/\/tutorialsclass.com\/#website\"},\"datePublished\":\"2020-05-26T15:42:47+00:00\",\"dateModified\":\"2020-05-26T15:42:48+00:00\",\"description\":\"Difference between GET and POST Method in PHP - The POST method transfers data via HTTP headers and GET method into a header called QUERY_STRING\",\"breadcrumb\":{\"@id\":\"https:\/\/tutorialsclass.com\/faq\/difference-between-get-and-post-method-in-php\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/tutorialsclass.com\/faq\/difference-between-get-and-post-method-in-php\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/tutorialsclass.com\/faq\/difference-between-get-and-post-method-in-php\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/tutorialsclass.com\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"FAQs\",\"item\":\"https:\/\/tutorialsclass.com\/faq\/\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"PHP Interview Questions\",\"item\":\"https:\/\/tutorialsclass.com\/faqs\/php\/\"},{\"@type\":\"ListItem\",\"position\":4,\"name\":\"All PHP Interview Questions &amp; Answers\",\"item\":\"https:\/\/tutorialsclass.com\/faqs\/php\/all-php-interview-questions-answers\/\"},{\"@type\":\"ListItem\",\"position\":5,\"name\":\"What is the difference between GET and POST method in PHP?\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/tutorialsclass.com\/#website\",\"url\":\"https:\/\/tutorialsclass.com\/\",\"name\":\"Tutorials Class\",\"description\":\"Online Tutorials for Beginners\",\"publisher\":{\"@id\":\"https:\/\/tutorialsclass.com\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/tutorialsclass.com\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/tutorialsclass.com\/#organization\",\"name\":\"Tutorials Class\",\"url\":\"https:\/\/tutorialsclass.com\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/tutorialsclass.com\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/tutorialsclass.com\/wp-content\/uploads\/2020\/05\/tutorials-class-logo.png\",\"contentUrl\":\"https:\/\/tutorialsclass.com\/wp-content\/uploads\/2020\/05\/tutorials-class-logo.png\",\"width\":442,\"height\":94,\"caption\":\"Tutorials Class\"},\"image\":{\"@id\":\"https:\/\/tutorialsclass.com\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/www.facebook.com\/tutorialsclass\",\"https:\/\/x.com\/TutorialsClass\",\"https:\/\/in.pinterest.com\/merientinfotech\/boards\/\",\"https:\/\/www.youtube.com\/channel\/UCzbpQXlqec-bQf1_kwrTuoA\"]}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Difference between GET and POST Method in PHP - Tutorials Class","description":"Difference between GET and POST Method in PHP - The POST method transfers data via HTTP headers and GET method into a header called QUERY_STRING","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/tutorialsclass.com\/faq\/difference-between-get-and-post-method-in-php\/","og_locale":"en_US","og_type":"article","og_title":"Difference between GET and POST Method in PHP - Tutorials Class","og_description":"Difference between GET and POST Method in PHP - The POST method transfers data via HTTP headers and GET method into a header called QUERY_STRING","og_url":"https:\/\/tutorialsclass.com\/faq\/difference-between-get-and-post-method-in-php\/","og_site_name":"Tutorials Class","article_publisher":"https:\/\/www.facebook.com\/tutorialsclass","article_modified_time":"2020-05-26T15:42:48+00:00","og_image":[{"width":600,"height":600,"url":"https:\/\/tutorialsclass.com\/wp-content\/uploads\/2020\/07\/tutorials-class-logo.png","type":"image\/png"}],"twitter_card":"summary_large_image","twitter_site":"@TutorialsClass","twitter_misc":{"Est. reading time":"3 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/tutorialsclass.com\/faq\/difference-between-get-and-post-method-in-php\/","url":"https:\/\/tutorialsclass.com\/faq\/difference-between-get-and-post-method-in-php\/","name":"Difference between GET and POST Method in PHP - Tutorials Class","isPartOf":{"@id":"https:\/\/tutorialsclass.com\/#website"},"datePublished":"2020-05-26T15:42:47+00:00","dateModified":"2020-05-26T15:42:48+00:00","description":"Difference between GET and POST Method in PHP - The POST method transfers data via HTTP headers and GET method into a header called QUERY_STRING","breadcrumb":{"@id":"https:\/\/tutorialsclass.com\/faq\/difference-between-get-and-post-method-in-php\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/tutorialsclass.com\/faq\/difference-between-get-and-post-method-in-php\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/tutorialsclass.com\/faq\/difference-between-get-and-post-method-in-php\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/tutorialsclass.com\/"},{"@type":"ListItem","position":2,"name":"FAQs","item":"https:\/\/tutorialsclass.com\/faq\/"},{"@type":"ListItem","position":3,"name":"PHP Interview Questions","item":"https:\/\/tutorialsclass.com\/faqs\/php\/"},{"@type":"ListItem","position":4,"name":"All PHP Interview Questions &amp; Answers","item":"https:\/\/tutorialsclass.com\/faqs\/php\/all-php-interview-questions-answers\/"},{"@type":"ListItem","position":5,"name":"What is the difference between GET and POST method in PHP?"}]},{"@type":"WebSite","@id":"https:\/\/tutorialsclass.com\/#website","url":"https:\/\/tutorialsclass.com\/","name":"Tutorials Class","description":"Online Tutorials for Beginners","publisher":{"@id":"https:\/\/tutorialsclass.com\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/tutorialsclass.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/tutorialsclass.com\/#organization","name":"Tutorials Class","url":"https:\/\/tutorialsclass.com\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/tutorialsclass.com\/#\/schema\/logo\/image\/","url":"https:\/\/tutorialsclass.com\/wp-content\/uploads\/2020\/05\/tutorials-class-logo.png","contentUrl":"https:\/\/tutorialsclass.com\/wp-content\/uploads\/2020\/05\/tutorials-class-logo.png","width":442,"height":94,"caption":"Tutorials Class"},"image":{"@id":"https:\/\/tutorialsclass.com\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/tutorialsclass","https:\/\/x.com\/TutorialsClass","https:\/\/in.pinterest.com\/merientinfotech\/boards\/","https:\/\/www.youtube.com\/channel\/UCzbpQXlqec-bQf1_kwrTuoA"]}]}},"_links":{"self":[{"href":"https:\/\/tutorialsclass.com\/wp-json\/wp\/v2\/faq\/6166","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/tutorialsclass.com\/wp-json\/wp\/v2\/faq"}],"about":[{"href":"https:\/\/tutorialsclass.com\/wp-json\/wp\/v2\/types\/faq"}],"author":[{"embeddable":true,"href":"https:\/\/tutorialsclass.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/tutorialsclass.com\/wp-json\/wp\/v2\/comments?post=6166"}],"version-history":[{"count":1,"href":"https:\/\/tutorialsclass.com\/wp-json\/wp\/v2\/faq\/6166\/revisions"}],"predecessor-version":[{"id":6167,"href":"https:\/\/tutorialsclass.com\/wp-json\/wp\/v2\/faq\/6166\/revisions\/6167"}],"wp:attachment":[{"href":"https:\/\/tutorialsclass.com\/wp-json\/wp\/v2\/media?parent=6166"}],"wp:term":[{"taxonomy":"faq_type","embeddable":true,"href":"https:\/\/tutorialsclass.com\/wp-json\/wp\/v2\/faq_type?post=6166"},{"taxonomy":"keywords","embeddable":true,"href":"https:\/\/tutorialsclass.com\/wp-json\/wp\/v2\/keywords?post=6166"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}