When you need to retrieve URL Data, PHP’s $_GET will get the job done.
See the ‘URL Request String Example’ at the bottom of the page before proceeding.
A Request is made by typing into a browser, or clicking a link. Once this happens, an HTTP GET Request has been made. It is called a Request, because you are requesting information from a remote computer. In this case, the remote computer exists at google.com, and the file being requested is registration.php.
You can also see that there is a question mark after the registration.php file. This question mark signifies that there is a data payload onboard. This means the remote computer is called at google.com, the registration.php file is requested, and three pieces of data are being sent as follows:
first_name = Tom
last_name = Slateron
class = accounting
The web works in a Request/Response cycle. A request is made from clicking a link or typing a URL string in the browser. A remote computer and file are called. The registration.php file then collects the data from the URL string, and begins processing your request. Once the Request has been processed, a Response is created. This Response is sent back to you in the form of a web page.
You make a REQUEST. The web server processes your request, and sends back a RESPONSE. This is the basic cycle of the web..
How Does the URL Data Get Processed
$_GET is one of many built in super global arrays in PHP. $_GET has one specific function. It retrieves data from a HTTP GET Request, which is the data in URL string.
From the registration.php file being called, it is very easy to retrieve the data from the URL string.
// collect the information from the URL string.
// set this data to 3 new variables to hold the data.
$firstName = $_GET['first_name'];
$lastName = $_GET['last_name'];
$class = $_GET['class'];
// now since we have the data from the URL string, let’s process it
// in a very simple way – let’s output this data out the screen.
That is all there is to it. Any letters, characters or numbers can be sent in the URL string. When it arrives at registration.php that data will be automatically stored in the Super Global Array $_GET, by the PHP engine. Your only task is to retrieve this data from the $_GET array and use it in your program.
The web works on a Request/Response Cycle. Clicking a link or typing a URL string in a browser creates a GET Request. The remote computer that is being called processes the data, and issues a Response. This Response is the web page that you wanted.
In PHP you can retrieve the data from a GET Request (URL String) with the Super Global Array $_GET.
URL Request Example
Paul Markovich is a Lead Technical Trainer.
He has been designing and building custom web sites for entrepreneurs since 1997. He’ll help you get the answers to your burning open source programming questions!