HOME C C++ PYTHON JAVA HTML CSS JAVASCRIPT BOOTSTRAP JQUERY REACT PHP SQL AJAX JSON DATA SCIENCE AI

PHP $_GET

a superglobal is a predefined variable that's accessible throughout your entire script, regardless of its scope (functions, blocks, etc.). One such superglobal variable is $_GET.

There are two main ways to send variables via the HTTP GET method:

• Query strings in the URL

• HTML Forms


• Query string in the URL


The query string is the part of a URL that follows the ? symbol and consists of one or more parameter-value pairs separated by & ampersands.




<a href="demo_phpfile.php?subject=PHP&web=codelines.in">Test $GET

The query string above contains two key/value pairs:

subject=PHP
web=codelines.in

In the PHP file we can use the $_GET variable to collect the value of the query string.



Example


The PHP file demo_phpfile.php:

<!DOCTYPE html>
<html>
<body>

<a href="demo_phpfile.php?subject=PHP&web=W3schools.com">Test $GET</a>

</body>
</html>

Output

Test $GET


• $_GET in HTML Forms


A HTML form submits information via the HTTP GET method if the form's method attribute is set to "GET".

To demonstrate this, we start by creating a simple HTML form:



HTML Form


<html>
<body>

<form action="welcome_get.php" method="GET">
  Name: <input type="text" name="name">
  E-mail: <input type="text" name="email">
  <input type="submit">
</form>

</body>
</html>

When a user clicks the submit button, the form data is sent to a PHP file specified in the action attribute of the <form> tag.