Are there any alternative methods to restrict access to a PHP page based on the referring page?

To restrict access to a PHP page based on the referring page, you can check the HTTP referer header in the request and only allow access if it matches a specific URL. This can help prevent unauthorized access to sensitive pages from external sources.

<?php
$allowed_referer = "http://example.com/referring-page.php";
$referer = $_SERVER['HTTP_REFERER'];

if($referer != $allowed_referer){
    header("HTTP/1.1 403 Forbidden");
    die("Access denied");
}

// Proceed with the rest of your PHP code here
?>