3

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.

Community
  • 1
  • 1
esafwan
  • 17,311
  • 33
  • 107
  • 166

1 Answers1

2

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.

Māris Kiseļovs
  • 16,957
  • 5
  • 41
  • 48
  • How will it be if it's hosted on a shared host or a reseller package? – esafwan Oct 10 '10 at 09:44
  • Depends. You can start with test what is returned by print $_SERVER['HTTP_HOST']; print $_SERVER['SERVER_NAME']; – Māris Kiseļovs Oct 10 '10 at 09:49
  • It's returning correctly... all the domains are being printed. But I'm afraid is there any circumstance whn thz will fail? Whats that ur where saying of load balancing & proxy and all.. I'm new to all this :) – esafwan Oct 10 '10 at 10:29
  • If it's returning correctly, then you can rely on these variables and it will work while your hosting provider will not totally change hosting configuration. Load balancing - http://en.wikipedia.org/wiki/Load_balancing_(computing) – Māris Kiseļovs Oct 10 '10 at 10:34
  • does this have any difference if I'm developing in codeigniter? – esafwan Oct 10 '10 at 11:50