Loading Depth Study
Preparing your workspace
PHP can receive HTTP request data through predefined variables such as $_GET and $_POST.
Web forms commonly send data to a PHP server using GET or POST. GET is generally used for retrieving resources and sending non-sensitive query information, while POST is commonly used for creating or submitting data. PHP exposes request values through superglobals such as $_GET and $_POST. Input should always be validated on the server because clients can send arbitrary values. Applications should also use output escaping and secure handling appropriate to the context.
A student registration page can send name and email information to PHP for server-side validation and account creation.
<?php
$name = trim($_POST['name'] ?? '');
$email = trim($_POST['email'] ?? '');
if ($name === '' || !filter_var($email, FILTER_VALIDATE_EMAIL)) {
echo 'Invalid input';
exit;
}
echo 'Registration data is valid';The script validates the submitted name and email and prints a suitable result.