How does PHP handle communication over HTTP and the delivery of HTML pages in a logged-in state?

PHP handles communication over HTTP by using built-in functions like cURL or the HTTP extension to make requests to external servers. To deliver HTML pages in a logged-in state, PHP can use sessions to store login information and check if a user is logged in before displaying protected content.

<?php
session_start();

// Check if user is logged in
if(isset($_SESSION['logged_in']) && $_SESSION['logged_in'] === true) {
    // Display protected content
    echo "Welcome, logged in user!";
} else {
    // Redirect to login page
    header("Location: login.php");
    exit();
}
?>