Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

I have a page and I would like to allow access to this page only from domains that I allow. What would be the best way of doing this?

share|improve this question

migrated from stackoverflow.com Jan 9 '12 at 2:08

This question came from our site for professional and enthusiast programmers.

closed as off topic by Mark Henderson Jan 9 '12 at 2:17

Questions on Server Fault are expected to relate to server, networking, or related infrastructure administration within the scope defined by the community. Consider editing the question or leaving comments for improvement if you believe the question can be reworded to fit within the scope. Read more about reopening questions here.If this question can be reworded to fit the rules in the help center, please edit the question.

2 Answers 2

You can start by checking $_SERVER['HTTP_REFERER'] variable. However, for protected resources you might want to set up a proper authorization, e.g. through a .htaccess file.

Examples:

http://php.net/manual/en/reserved.variables.server.php

http://www.thelinuxblog.com/htaccess-allow-from/

share|improve this answer

use $_SERVER['HTTP_REFERER'] to check what website is accessing your page and compare it with your list of website.

user it in the header part of your page like following,

if($_SERVER['HTTP_REFERER']=="http://example.com")
{
   echo do something;
}
else
{
   echo "no access";
}
share|improve this answer