Skip to content
Learn Netverks

Lesson

Step 23/36 64% through track

get-post

Handling GET and POST

Last reviewed May 28, 2026 Content v20260528
Track mode
server_script
Means
Server runner
Reading
~2 min
Level
intermediate

This lesson

This lesson teaches Handling GET and POST: the syntax, APIs, and habits you need before advancing in PHP.

HTML forms map directly to $_POST—this is where most learner bugs and XSS risks appear.

You will apply Handling GET and POST in contexts like: Contact forms, registration, and settings pages posting back to PHP scripts.

Write PHP in the editor and click Run on server—the dev runner executes your script and returns stdout/stderr (set LEARNING_RUNNER_ENABLED=true locally).

When you can explain the previous lesson's ideas without copying starter code.

HTML forms and links send data via HTTP methods. PHP exposes query strings in $_GET and form bodies in $_POST.

GET — read, idempotent, bookmarkable

<a href="/search.php?q=php&page=2">Page 2</a>
$q = trim($_GET['q'] ?? '');
$page = max(1, (int) ($_GET['page'] ?? 1));

POST — mutations, larger payloads

<form method="post" action="/subscribe.php">
  <input name="email" type="email">
</form>
$email = filter_input(INPUT_POST, 'email', FILTER_VALIDATE_EMAIL);

Method selection

Use GET for safe reads (search, filters). Use POST for creates/updates/deletes. REST APIs also use PUT/PATCH/DELETE—often via frameworks or $_SERVER['REQUEST_METHOD'].

Playground note

Assign sample arrays to simulate input—the validation logic is what you practice here.

Important interview questions and answers

  1. Q: Why not put passwords in GET?
    A: Query strings appear in logs, history, and Referer headers—use POST over HTTPS.
  2. Q: filter_input vs raw $_POST?
    A: filter_input applies validation/sanitization filters in one step.

Self-check

  1. Which superglobal holds ?page=2?
  2. Why validate email with FILTER_VALIDATE_EMAIL?

Challenge

Sanitize a search query

  1. Simulate $_GET['q'] with extra spaces.
  2. Trim and reject empty queries.
  3. Echo the cleaned value.

Done when: output shows a trimmed, non-empty search string.

Interview prep

GET vs POST?

GET for safe, idempotent reads in the query string; POST for mutations and sensitive data in the body—never passwords in GET.

Interview tip Lesson completion confidence

Can you explain this lesson in 30 seconds without reading notes?

Not saved yet.

Playground

Runs on the configured server runner (dev: npm run runner with LEARNING_RUNNER_ENABLED=true). Output appears below the editor.

Check yourself

Multiple choice — immediate feedback.

Discussion

Past discussion is visible to everyone. Only logged-in users can post comments and replies.

Starter discussion topics

  • GET idempotent?
  • POST resubmit risk?

Sign up or log in to post comments and sync lesson progress across devices.

No discussion yet. Be the first to ask a question.

Jump