Junior — Middle
How does a server accept and interpret an incoming HTTP GET request?
sobes.tech AI
Answer from AI
When the server receives an HTTP GET request, it first accepts a TCP connection on a specific port (usually 80 or 443). Then the server reads the request headers, including the method (GET), URL, parameters, and other data. After that, the server interprets the URL and parameters, determines which resource or script to execute, and hands over control to the appropriate handler (for example, a PHP script). In PHP, GET parameters are accessible through the superglobal array $_GET.
Example of handling a GET request in PHP:
// URL: example.com/page.php?user=123
$userId = $_GET['user'] ?? null;
if ($userId) {
echo "User ID: " . htmlspecialchars($userId);
} else {
echo "User ID not specified";
}