Skip to content

Chapter 12 of 38

Forms: GET and POST

Process form methods, encoding, validation, CSRF, redirects, and user feedback.

40 minutes 10 quick checksBy Subha Prasad
Lesson 12 of 38Course navigation

Lesson content

Read, practise, then check your understanding

GET represents safe retrieval and exposes fields in the URL; POST carries a body and commonly performs change. HTTPS—not method choice—provides transport confidentiality.

Practical example

<?php
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
  $email = filter_input(INPUT_POST, 'email', FILTER_VALIDATE_EMAIL);
  if ($email === false || !hash_equals($_SESSION['csrf'], $_POST['csrf'] ?? '')) { http_response_code(422); exit; }
  header('Location: /success', true, 303); exit;
}

Use the correct upload enctype, enforce every rule server-side, and implement CSRF protection for authenticated state changes. Post/Redirect/Get prevents refresh resubmission. Escape redisplayed values for their exact output context.

Knowledge check

Answer every question correctly to complete this chapter.

Which statement best describes GET?
Which PHP term matches this description: A request method placing form data in the URL query and suited to safe retrieval.
Which statement best describes POST?
Which PHP term matches this description: A request method carrying form data in the request body.
Which statement best describes request method?
Which PHP term matches this description: The HTTP method available through server request metadata.
Which statement best describes CSRF token?
Which PHP term matches this description: An unpredictable per-session/request value verifying intentional form submission.
Which statement best describes Post/Redirect/Get?
Which PHP term matches this description: A pattern redirecting after mutation to prevent accidental resubmission.

0 of 10 checks passed

Your progress is saved on this device.

Forms: GET and POST | PHP Lesson | Subha Prasad