0% complete

Superglobals · Lesson 1 of 8

$_GET

Read query-string values from the GET superglobal.

Lesson

$_GET is an associative array of URL query parameters. Treat its contents as untrusted strings or arrays: check the expected shape, validate the value, and set sensible limits. Query parameters are visible in browser history, access logs, and referrer data. Use a validated scalar for a search or page filter, not for secrets or an authorization decision. Further guidance Superglobal values come from the request or process environment and can be missing or have an unexpected type. Check the key and shape before use, validate it for the operation, and avoid printing secrets or trusting client-controlled headers. Prefer the specific input source over merged request data. Practice task: Create a fresh example for $_GET. Predict the result before running it, then change one input and explain why the result changes. Test a normal case and one boundary or invalid case where it applies. Compare your output with the example and note one rule you would use in a real project.

Code examples

$_GET
PHP
$query = $_GET['q'] ?? '';
if (is_string($query)) {
    echo 'Searching for: ', htmlspecialchars($query, ENT_QUOTES, 'UTF-8');
}
Expected output
An escaped search phrase

Key points

  • Read query-string values from the GET superglobal.
  • Treat request and environment values as untrusted input.
  • Check the expected type and presence before using a value.

Your learning progress

Finish this lesson

Optional practice

PHP playground

This site does not execute learner-provided PHP code. Connect a secured PHP sandbox service before enabling code execution.

Execution is disabled. No code is sent to a server.