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

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
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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.