• Howdy! Welcome to our community of more than 130.000 members devoted to web hosting. This is a great place to get special offers from web hosts and post your own requests or ads. To start posting sign up here. Cheers! /Peo, FreeWebSpace.net
managed wordpress hosting

hey experts, deciphering HTTP_HOST in php, similar to perl?

keith

anti-liberal
NLC
ok, say i want a file to load in perl based on the hostname, i'd have it read something like this:
Code:
$host = "$ENV{'HTTP_HOST'}";

if ($host =~ /spacetwins\.com/) {
include "file.txt";
}
this way, it will load the file anytime spacetwins.com is loaded, www.spacetwins.com, anus.spacetwins.com, anything.spacetwins.com... you get the picture...



so how would this be done in php? i have:
Code:
<?
if ($HTTP_HOST =~ "spacetwins.com") {
include"file.txt";
}
?>
but that doesn't work. i'd have to have:
Code:
<?
if ($HTTP_HOST == "www.spacetwins.com" || $HTTP_HOST == "spacetwins.com") {
include"file.txt";
}
?>
i have to include every hostname, instead of just relying on the wildcard.


how would i modify that for php, so it deciphers it like in perl, based on the root hostname?
 
hmmm, doesn't seem to work, am i using it correctly?
Code:
<?

eregi("spacetwins.com",$HTTP_HOST) {
include("spacetwins.php");
}

eregi("weezerfans.com",$HTTP_HOST) {
include("weezerfans.php");
}

?>
 
Back
Top