I’ve been banging my head against this for a week. I have a page that we want to only be accessible from another domain. Is it possible with PHP or .htaccess? Ive posted a couple attempts to do this on here, nothing seems to work. Please help!
<?php
$allowed_domains = array('dirtybirddesignlab.com','foo.com');
$REFERRER = $_SERVER['HTTP_REFERER'];
if ($REFERRER == '') {
exit(header('Location: 404.php'));
}
$domain = substr($REFERRER, strpos($REFERRER, '://')+3);
$domain = substr($domain, 0, strpos($domain, '/'));
if (!in_array($domain, $allowed_domains)) {
exit(header('Location:404.php'));
}
?>
To expand on my comment, see the line
if ($REFERRER == '')block.Note, the above will fall through to always referring those browsers that haven’t reported a referrer to be redirected to the error.php page.
My suggestion is to do something like…
For instance…
Their domain
Your domain – include(‘/path/to/domaincheck.php’)
Notice both the $dsalts are the same. I generated that with puttgen.exe.
Something along those lines. You will need to handle cases in which the key may expire, or whatnot. Another method may be to share valid $dkey’s between your servers with a timestamp and expire them after a certain amount of time (maybe one hour).
theirserver.com and yourserver.com
Browser