HTTP is stateless. PHP HTTP requests generated by a user by typing a URL in browser is translated depending upon the resource requested. It may translate to a web page with HTML extension, a .png file, a .flash file or simply a style sheet CSS file. It does not retain any information about the resources being accessed or the client from which it has obtained the request.

HTTP does not remember the navigation between web pages. It is the browser application you use which access web pages retains the sequence of pages followed through its next or previous buttons. Almost every browser contains the history tool that records the web pages visited by a user with data and time.

In short PHP HTTP Requests cannot be used to set the variables on one page and referred or used in another page for processing or calculation. HTTP can also not be used for creating a form and retaining the values typed in by the user. A programmer has to use other mechanism offered by a scripting language to pass information from one page to another page or program of a website.

Form handling with HTTP requests capability of PHP is used to save the variables in one page and passed to next one. PHP is characterized by its capability to pass on data making it faster and easier for creating interactive web applications and sites. Two methods for doing this are GET and POST.

GET METHOD

Get method passes arguments from one page to next page as part of the URL query string. When used for form handling, GET appends the indicated variable names and their values to the URL designated in the action attribute of the form. These are appended after “?” and different variables and values pairs are separated by “&”. This whole string is submitted to the local or remote server for processing.

<form action=“GET.php” method=“GET”>

When a user enters some values in the web form or selects some options and clicks the submit button, the browse collects the elements in their order of appearance in the form with no spaces between the elements. The URL is address bar looks like this

http://www.csveda.com/GET.php?uname=John&pwd=john123#

It has these four elements

  • URL in quotes after action
  • A “?” indicating that after this a GET string is following. It is called the querystring
  • A variable name , equal sign and the value of the variable
  • An “&” ampersand and next variable name and value pair

GET method advantages

A new and distinct string is constructed as URL query string that can be book marked or cached.

GET method disadvantages

  • GET method doesn’t translate the values in the query string so it is visible in the browser address space. It also gets stored in the visited page history of the
  • Every GET submission is recorded in the web server as well as the data set
  • Limited to characters count imposed by browser application you are using and the webserver.

POST METHOD

POST method in HTTP is used for submitting data inputted by user in large forms to the server for storage. The values are not visible in the URL as query string but encoded in a separate part of the HTTP request. The POST method requests cannot be cached and each request is independent from other requests.

Since POST requests are not exposed in the URL so it may be used for sending sensitive data from one page to another. Data can still be accessed so to ensure complete security, the data must be encrypted in case you are developing a secure web application.

There is no limit of form control values passed using POST. You can use it for passing on large amout of form data to server for storage.

<form action=”POST.php” method=”POST”>

POST method advantages

  • Encoded data is not visible in the URL
  • No limit on data, so a POST method can be used for transferring large amount of form data to the database server.

POST method disadvantages

  • Data is still not secure. It is need to be secured with a suitable encryption algorithm.
  • URL cannot be book marked or cached.

Associative Arrays for PHP HTTP Requests- GET and POST

Related to PHP HTTP requests GET and POST methods PHP offers two associative arrays $_GET and $_POST that carry the values from the page on which form action and method is defined to the .php script called. The form elements pass their values to either of these arrays as per defined method for current HTML form.