The front controller is the single entry point for all HTTP requests to Zoo Arcadia. Located at public/index.php, it acts as “The Porter” - receiving every request and deciding how to handle it.
A front controller is a design pattern where a single component handles all incoming requests and routes them to appropriate handlers. This provides:
Centralized request handling: All requests go through one point
Consistent processing: Same initialization logic for every request
Security: Single point to enforce security policies
Clean URLs: Hide .php extensions and internal structure
In production, the web server (Apache/Nginx) is configured to route all non-file requests to public/index.php. This is what enables clean URLs like /animals/pages/allanimals instead of /App/animals/controllers/animals_pages_controller.php?action=allanimals.
Before starting any session, the front controller configures secure session cookie parameters:
session_set_cookie_params([ 'lifetime' => 0, // Session cookie (expires on browser close) 'path' => '/', // Valid across entire site 'secure' => isset($_SERVER['HTTPS']), // HTTPS only if available 'httponly' => true, // Prevents JavaScript access 'samesite' => 'Lax' // CSRF protection]);
Session Cookie Security Explained
lifetime = 0: The session cookie is temporary and expires when the user closes their browser. This prevents long-lived session cookies from being stolen.path = ’/’: The cookie is valid across the entire website, not just subdirectories.secure = isset($_SERVER[‘HTTPS’]): In production with HTTPS, the cookie can only be transmitted over secure connections. This prevents man-in-the-middle attacks.httponly = true: JavaScript cannot access the session cookie via document.cookie. This prevents XSS attacks from stealing session tokens.samesite = ‘Lax’: The cookie is sent with same-site requests and top-level navigation (like clicking a link). This prevents CSRF attacks while maintaining usability. The alternative ‘Strict’ would be more secure but would log users out when arriving from external links.
The front controller serves static files from multiple locations (src/, node_modules/, public/, build/). This is useful during development but should be handled by the web server (Apache/Nginx) in production for better performance.