What are the advantages and disadvantages of using sessions versus cookies for controlling access to restricted pages in PHP?

Using sessions for controlling access to restricted pages in PHP offers more security as the session data is stored on the server-side. This prevents users from tampering with the data. On the other hand, cookies store data on the client-side, making them vulnerable to manipulation. However, sessions require server resources to store the data, which could potentially impact performance.

<?php
session_start();

// Check if user is logged in
if(!isset($_SESSION['loggedin']) || $_SESSION['loggedin'] !== true) {
    header("Location: login.php");
    exit;
}
?>