Forms & User Input · Lesson 2 of 6
GET Method
Read query parameters for safe, shareable requests.
Lesson
GET parameters are part of the URL and are appropriate for searches, filters, and pagination. They can be bookmarked and cached, so do not put passwords or private data in them. Validate presence, type, and allowed range before using a query value.
This handler validates a page number and falls back when the query is malformed.
Further guidance
Treat every submitted field and uploaded file as untrusted. Validate type, length, allowed values, and request method on the server; use CSRF protection for state changes. Escape values for their output context, and never use browser validation as the only safeguard.
Practice task: Create a fresh example for GET Method. 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 Method
PHP
$page = filter_input(INPUT_GET, 'page', FILTER_VALIDATE_INT);
$page = $page !== false && $page !== null && $page > 0 ? $page : 1;
echo "Page $page";
Expected output
Page 1 (when no valid page is provided)
Key points
- Read query parameters for safe, shareable requests.
- Validate input on the server before processing it.
- Escape output for its context and protect state-changing forms from CSRF.
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.