Question

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 domain 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.

Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top