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
?>
Related Questions
- In the context of a reservation system, what are some best practices for handling date comparisons and availability checks in PHP code?
- What best practices should be followed when handling user authentication in PHP scripts?
- What are common pitfalls when using PHP to interact with databases, and how can they be avoided?