I have a website with four versions depending on the device accessing it. Remember when duplicating the content of websites was a huge no-no a few years back? I’ve begun using PHP includes to keep them all alike when I make changes. To complicate things further, two of each version of the website are on two different domains. I know that was frowned upon in those old ‘scramble for search position’ days, but this is a special case IMHO. It’s actually easy to copy the new include file to both domains and they all say the same thing when I make a change. I need a PHP script to determine what domain name the surfer came from, and then echo a letter or a blank depending on which one. I already have a script that uses print root_domain and echo in a few places from a give-away script I adapted. Unfortunately I’m so inept I can’t get to the next step to just echo a letter for one domain or blank for the other.
Here’s my best guess:
[php]function GetRootDomain ()
{
$URL = strtolower($_SERVER[“HTTP_HOST”]);
$URL = preg_replace('/www\./', '', $URL);
$URL = parse_url(strtoupper($URL));
if (!empty($URL["host"])) {
return $URL["host"];
} else {
return $URL["path"];
}
}
//good above
$root_domain = GetRootDomain();
if ($root_domain=“ex.com”)
{
echo "t" ;
}
else
{
echo “x” ;
}[/php]
The comment in the middle marks a working script. When I use this script I get the first echo output every time. Any help would be appreciated.