How can access to a PHP page be restricted to only another specific PHP page?
To restrict access to a PHP page to only another specific PHP page, you can check the referring page in the HTTP headers of the request. If the referring page matches the specific PHP page you want to allow access, you can continue executing the code on the restricted page. Otherwise, you can redirect the user or display an error message.
<?php
// Check if the referring page is the specific PHP page
$referring_page = $_SERVER['HTTP_REFERER'];
if($referring_page != 'http://example.com/allowed_page.php'){
// Redirect or display an error message
header('Location: http://example.com/error_page.php');
exit();
}
// Continue executing the code for the restricted page
echo "You have access to this page.";
?>