What are the limitations of using referer checks in .htaccess files to restrict access to PHP scripts and how can they be bypassed?

Using referer checks in .htaccess files to restrict access to PHP scripts is not a foolproof method as the referer header can be easily manipulated or spoofed by an attacker. To enhance security, it is recommended to incorporate additional authentication mechanisms such as using session tokens or implementing user authentication.

<?php
session_start();

if (!isset($_SESSION['authenticated'])) {
    header('HTTP/1.1 403 Forbidden');
    exit;
}

// Your protected PHP script code here