Page 1 of 1

subdomains in PHP

Posted: Sun Oct 10, 2004 5:46 am
by jasongr
Hello

I am not sure if this question should be posted here, but since I am writing my application in PHP and I am sure someone here will know the answer, I will try. (in the worst case, please move this post somewhere else)

My application needs to perform certain actions if a subdomain was used in accessing the server.
For example, the URL http://dummy1.test.com should trigger a different behaviour than the URL http://www.test.com or http://test.com

Is there a way to obtain the subdomain part in the host without parsing it manually from the $_SERVER['HTTP_HOST'] value?

Also, can it be tested locally?
Usually when I debug my application I surf using http://localhost/
Is there a way to simulate a subdomain on the local machine?

regards

Posted: Sun Oct 10, 2004 6:16 am
by mudkicker
you should look at Apache's module -> mod_rewrite

Posted: Sun Oct 10, 2004 6:27 am
by timvw
could simply search in this forum, cause i remember posting a solution a while ago

Posted: Sun Oct 10, 2004 10:07 am
by feyd
for finding what domain the script is being accessed under: $_SERVER['HTTP_HOST'] and $_SERVER['SERVER_NAME']

As for creating subdomains for testing; depending on your OS, there's virtual hosts and the hosts file. On my machine, changing the hosts file alone, caused both values to switch to the "new" name.

The hosts files is located at:
%WINDIR%\system32\drivers\etc\hosts

Posted: Sun Oct 10, 2004 10:31 am
by jasongr
Thanks

This is what I needed
Justed added the appropriate mapping:

127.0.0.1 dummy.test.com

and it worked