How can PHP be utilized to display custom messages to users attempting to access a restricted page on a website?
When a user attempts to access a restricted page on a website, PHP can be utilized to display a custom message informing them of the restriction. This can be achieved by checking the user's credentials or permissions before allowing access to the page. If the user does not have the necessary permissions, a custom message can be displayed using PHP.
<?php
session_start();
if(!isset($_SESSION['logged_in']) || $_SESSION['logged_in'] !== true) {
echo "You do not have permission to access this page. Please log in.";
exit;
}
// Restricted page content here
?>