How can PHP be used to restrict access to certain folders on a website?

To restrict access to certain folders on a website using PHP, you can create a .htaccess file in the folder you want to protect and use PHP to check if the user is authorized to access the folder. You can set up authentication using PHP sessions or user credentials stored in a database. Here is an example of how you can use PHP to restrict access to a folder:

<?php
session_start();

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