What are the potential ways to centralize access control in a PHP application, such as through index.php or bootstrap.php?

Centralizing access control in a PHP application can be achieved by using a single entry point like index.php or bootstrap.php to handle all incoming requests. This allows for consistent enforcement of access control rules and reduces code duplication. By routing all requests through this centralized file, you can easily manage authentication, authorization, and other security measures in one place.

// index.php

// Include necessary files and configurations
require_once 'bootstrap.php';

// Check user authentication
if (!isLoggedIn()) {
    header('Location: login.php');
    exit;
}

// Route the request to the appropriate controller
$controller = $_GET['controller'] ?? 'home';
$action = $_GET['action'] ?? 'index';

// Include the controller file
require_once 'controllers/' . $controller . '.php';

// Call the appropriate action method
$controllerInstance = new $controller();
$controllerInstance->$action();