954,576 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

sub-domains

i have two sub-domains pointing at the same file.the sub-domain's are test.test.com and fail.test.com and the file is index.php. Now i want to be able to work with both of those domains within the same file so i used this code:

if($_SERVER['HTTP_HOST']=='test'){
	echo"test";
}else if($_SERVER['HTTP_HOST']=='fail'){
echo"fail";
}

but it will not work. can anybody help? thanks in advanced

tcollins412
Junior Poster
139 posts since Dec 2010
Reputation Points: 10
Solved Threads: 3
 

I don't understand how you have this configured. Normally sub-domains are entirely separate and don't share the same code. You could have parked domains pointing to another domain and then they would all be treated the same and share the same code but that is entirely different. In that case, you can check which domain name was used in the (common) code.

Please clarify.

chrishea
Nearly a Posting Virtuoso
1,428 posts since Sep 2008
Reputation Points: 210
Solved Threads: 230
 

@chrishea
I have a development server where projects get subdomains configured as virtual hosts all other unmatched subdomains resolve to a single catch-all vhost. I don't think it is terribly uncommon just depends on the usage.

@tcollins
If you call <?php phpinfo(); ?> from that file and look though the results for HTTP_HOST and it's value, you will probably see that the HTTP_HOST is test.domain.com or fail.domain.com, not just the subdomain portion.

mschroeder
Work Harder
Team Colleague
666 posts since Jul 2008
Reputation Points: 279
Solved Threads: 131
 

thank you

tcollins412
Junior Poster
139 posts since Dec 2010
Reputation Points: 10
Solved Threads: 3
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: