[SOLVED] subdomains in PHP

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
jasongr
Forum Contributor
Posts: 206
Joined: Tue Jul 27, 2004 6:19 am

subdomains in PHP

Post 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
User avatar
mudkicker
Forum Contributor
Posts: 479
Joined: Wed Jul 09, 2003 6:11 pm
Location: Istanbul, TR
Contact:

Post by mudkicker »

you should look at Apache's module -> mod_rewrite
timvw
DevNet Master
Posts: 4897
Joined: Mon Jan 19, 2004 11:11 pm
Location: Leuven, Belgium

Post by timvw »

could simply search in this forum, cause i remember posting a solution a while ago
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post 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
jasongr
Forum Contributor
Posts: 206
Joined: Tue Jul 27, 2004 6:19 am

Post by jasongr »

Thanks

This is what I needed
Justed added the appropriate mapping:

127.0.0.1 dummy.test.com

and it worked
Post Reply