How can I detect entry to a website by domain?
If I have multiple domain entry points and want to use the same hosting, can I detect by way of PHP or JavaScript what domain that person came though to the hosting website?
ie: I have 3 domains:
www.jackfrost.com
www.holycow.com
www.ohmy.com
Hosting is under www.jackfrost.com.
So if somebody comes in through www.ohmy.com, can I detect that, so I only display content for that entry and different cont开发者_C百科ent for a different entry?
(purpose is to keep costs down since the websites are hosted by godaddy)
The best way you can do is to have a look at $_SERVER['HTTP_HOST']
in your PHP script and dispatch your content based on that.
In JavaScript, you can check window.location.hostname for the domain name used.
However, a better way would be to have three different virtual hosts in your webserver configuration - one for each domain you have. This way, even without PHP or any other scripting language, you can have different content for different domains. When using Apache as webserver, you can have a look at the documentation with examples: http://httpd.apache.org/docs/2.2/vhosts/examples.html.
If you do not want or can use name based virtual hosting, you can use only one virtual host, and use mod_rewrite of Apache to internally rewrite requests to other directories based on HTTP_HOST
.
If you are using Apache you should set up name-based virtual hosts.
Apache V1
http://httpd.apache.org/docs/1.3/vhosts/name-based.html
Apache V2
http://httpd.apache.org/docs/2.0/vhosts/
精彩评论