PHP was designed specifically for the web. Unlike general-purpose languages adapted for web use, PHP:
$_GET, $_POST, $_SESSION)This transparency makes HTTP concepts visible in ways frameworks obscure.
Understand the request-response cycle. See what happens when PHP runs on the server.
Read user input from forms. Learn about GET vs POST and security essentials.
$_GET and $_POSTWork with HTTP headers. Build APIs and handle different content types.
$_SERVER superglobalMaintain state across requests. Build login/logout flows.
session_start()$_SESSION arraycd php-tutorial php -S localhost:8000
Then visit http://localhost:8000/
| Variable | Contains |
|---|---|
$_GET |
URL query parameters (?key=value) |
$_POST |
Form data from POST requests |
$_COOKIE |
Cookie values |
$_SESSION |
Session data (after session_start()) |
$_SERVER |
Server and request metadata |
$_FILES |
Uploaded file information |
// Output
echo "Hello"; // Output string
print_r($array); // Debug array
// Security
htmlspecialchars($str, ENT_QUOTES, 'UTF-8') // Escape HTML (XSS prevention)
// Headers (must be before any output!)
header('Content-Type: application/json'); // Set content type
header('Location: /other.php'); // Redirect
http_response_code(404); // Set status code
// Sessions
session_start(); // Start/resume session
$_SESSION['key'] = 'value'; // Store in session
session_regenerate_id(true); // Security: new session ID
session_destroy(); // End session
// JSON
json_encode($data); // PHP array to JSON string
json_decode($json, true); // JSON string to PHP array