In PHP, $_GET is a predefined superglobal variable that contains the values of query parameters passed in the URL of an HTTP GET request. This means that $_GET is used to collect values that are passed in the URL as key-value pairs.

Here’s an example of a URL that contains query parameters:

In this example, the query parameters are q=PHP and sort=date , where q is the search query and sort is the sort order. When this URL is requested using the HTTP GET method, the values of these parameters are available in the $_GET array.

In search.php , we can access the query parameters using $_GET :

$query = $_GET['q'];
$sort = $_GET['sort'];

This code assigns the values of the q and sort query parameters to the $query and $sort variables using $_GET.

It is important to note that $_GET should only be used for non-sensitive data, as the values are visible in the URL and can be easily modified by the user. Additionally, it’s important to validate and sanitize input data before using it in your code to prevent security vulnerabilities like SQL injection attacks.

Overall, $_GET is an important tool for handling query parameters in PHP and is commonly used in web development.

Scroll to Top