Forum Moderators: coopster
if (($_SERVER['HTTP_HOST'] == "example.co.uk") OR ($_SERVER['HTTP_HOST'] == "www.example.co.uk"))
{
$titlebar='¦ Winterwind PvP';
$title='<map name="homepage"><area shape="rect" href="http://www.example.co.uk/index.php" coords="39,40,417,101" /></map><img src="sitemain/title.png" border="0" usemap="#homepage" />';
$nav='example.co.uk">Example';
} else if (($_SERVER['HTTP_HOST'] == "example.co.uk") OR ($_SERVER['HTTP_HOST'] == "www.example.co.uk"))
{
$titlebar='¦ Example PvP';
$title='<map name="homepage"><area shape="rect" href="http://www.example.co.uk/index.php" coords="39,40,417,101" /></map><img src="sitemain/rrtitle.png" border="0" usemap="#homepage" />';
$nav='example.co.uk">Example site';
} This is located outside of any function
I am then trying to pull the variables inside the same .php file, inside an echo command, like so:
echo ' ...snip... <td colspan="3" height="200" width="800">' . $title . '</td> ...snip... '; With similar for the other variables.
However, when trying to run this script, I'm just left with a blank space where I am trying to echo the variable; other than that, the page is working fine.
Any assistance in this matter would be very greatly appreciated :)
[edited by: eelixduppy at 10:44 pm (utc) on Dec. 13, 2009]
[edited by: dreamcatcher at 12:35 am (utc) on Dec. 14, 2009]
[edit reason] exemplified [/edit]
To Rocknbil: I know that the if statement itself is working, a simple echo command inside works fine and it does differentiate between the two URLs. Thanks for the advice about making it case-insensitive though. Cheers for the welcome too :)
To Dreamcatcher: Error reporting confirmed my suspicions that the variable declaration wasn't working, stating that there were several undefined variables. I can't see anything wrong with my syntax though :/
Both of these could be present at the same time, so you'd see "example.com.:80".
So unless you've got some code elsewhere (e.g. in a .htaccess file) that will redirect requests for non-canonical hostnames back to the canonical hostnames, your exact-match test will fail in any of those three cases.
For SEO reasons, I strongly recommend that you implement some code to force domain canonicalization and 'fix' all of these www/non-www/FQDN/port issues before invoking PHP. But if you don't do that, then consider using a regular-expressions pattern match to test HTTP_HOST, using something like
^(www\.)?example\.com\.?(:[0-9]+)?$
This one pattern in a preg_match will handle all those www/non-www, FQDN, and port variations of the hostname.
Jim
On a general note: I've put the if statements inside the actual functions on my format.php now so I don't need to have the variables as a function(argument) - saves me having to modify the entire site if I decide to make adjustments.
I hope you actually tested this. If you did get a 404 error then that's technically not a good thing, because requests for FQDN hostnames and with appended port numbers are quite valid. Instead, these requests should be 301-redirected to the canonical hostname.
Note that in your DNS settings, each domain specified in an "A record" must end with a period, because a fully-qualified domain name is *required* in DNS zone files. I'm mentioning that in case you have any doubts about such hostnames being valid.
I've described best practices here. It's your option whether to follow them or not.
Jim
I'm not 100% certain of the syntax for the preg_match, but I also don't want to be flat out told it as I'll never actually learn it that way. I shall have a few attempts when I'm back at the PC that has the files on.