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?

link|improve this question
feedback

migrated from stackoverflow.com Jan 9 at 2:08

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

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

Questions on Server Fault are expected to generally relate to servers, networking, or desktop infrastructure, within the scope defined in the faq.

2 Answers

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/

link|improve this answer
feedback

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";
}
link|improve this answer
feedback