What are the potential pitfalls of using JavaScript to control access to hidden pages on a website?

Potential pitfalls of using JavaScript to control access to hidden pages on a website include the risk of users easily bypassing the JavaScript restrictions by disabling or modifying the code in their browser. To solve this issue, access control should be implemented server-side using a more secure language like PHP.

<?php
session_start();

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

// Display hidden page content
echo "Welcome to the hidden page!";
?>