Reliability of php HTTP_HOST & HTTP_REFERER for critical task
I'm going to develop a website in PHP. But not sure if the method i'm going to use is the best approach. There will be many addon domains for the same site. But content will be filtered based on the domain used to visit the site.
For Example If a user comes from the domain siteusa.com then the content will be shown filtered accordingly specific user. If the user comes from siteuk.com/sitechina.com the content will be filetered accordingly etc...
I'm planning to do something like this to detect the url and serve content
$ref = getenv("HTTP_REFERER");
echo $ref;
or by
$host = $_SERVER['HTTP_HOST'];
echo $host ;
Is this is the best method to do this? Is there any possible bottleneck I may get into? This should not fail to detect the domain as its critical.
The main domai开发者_JAVA百科n of the site will be serving unfiltered content and each addon domain will filter it according to filter set for each domain from backend.
There is a smilar question but in regard with codeigniter here.
HTTP_REFERER is a bad choice. HTTP_REFERER will be empty when user visits your site directly.
HTTP_HOST/SERVER_NAME should do the trick but it can fail behind load balancing software or proxy.
So, it depends on your servers configuration. If you have access to hosts configuration (apache virtualhosts, for example), you can simply specify ENV variable in each VirtualHost for each domain.
精彩评论