PHP Form get


The $_GET variable is used to receive the form information sent by the form method = "get".


PHP $_GET

$_GET variable data structure with $_POST similar, but also an associative array, the key name for the form element name, used to collect HTTP GET request data.

Form form.php:

<html>
<body>
<form name = "commentform" method = "get" action = "comment.php">
<p>
Salutation: <input type = "text" name = "nickname" />
</p>
<input type = "submit" value = "Submit" />
</form>
</body>
</html>

The previous example form to GET mode, enter the address, the browser address bar, looks similar to the following(IE browser may be encoded by encode):

http://www.developertut.com/html/comment.php?nickname=john

Get GET form data:

echo 'Your name is : ' . $_GET["nickname"];
// Output: Your name is : john

Tip

  1. GET method will form data exposed in the browser address bar, it is not appropriate to send sensitive data(such as passwords, etc.), sensitive information sent using POST mode.
  2. The GET method has some restrictions on the amount of information sent. if you send large messages, use the POST method.
  3. GET pages can be accessed by adding a favorite in the future can be directly accessed, and POST mode to access the page can not.

HTTP GET

The HTTP GET method is used not only for form data transmission, but also for a more general way of obtaining the information of the resource specified by the request URL(browser address).

Using HTTP GET method can also be passed to the Web page data, such as the following address:

http://www.developertut.com/html/article.php?id=10

In this example, a message with id = 10 is passed to article.php via the address GET method. In article.php can be achieved through $_GET["id"] data, the actual role may be read from the database id 10 of this article, a number of data to connect with the ampersand:

http://www.developertut.com/html/article.php?type=2&id=10

Get the GET data in article.php:

echo $_GET["type"]; // Output 2
echo $_GET["id"]; // output 10

PHP $_REQUEST

The $_REQUEST variable is also predefined in PHP, which contains $_POST, $_GET, and $_COOKIE. Its access with $_POST, etc.:

echo $_REQUEST["nickname"] // Output the user-entered title
echo $_REQUEST["id"]; // output 10



Copyright 2014-2017 by DeveloperTut.com. All Rights Reserved.
TwitterGoogle+Facebook