PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
I am trying to use the $_SERVER['HTTP_HOST'] , to show html at the top of the page. (for every "parked" name on my server points only to one website but when someone goes on the site and types in for ex. yahoo.com, or excite.com thats what shows up at the top, ONLY it has to be in html so i can change the look of it)
<?
/// Start Settings ////
$yahoo='<b><font style="FONT-SIZE: 24pt" face="Verdana"><font color="#000080">
Yahoo</font><i><font color="#ff0000">.com</font></i></font></b>';
$excite='<b><font style="FONT-SIZE: 24pt" face="Verdana"><font color="#000080">
Excite</font><i><font color="#ff0000">.com</font></i></font></b>';
/// End Settings ////
/// List Functions
if($_SERVER['HTTP_HOST'] == "yahoo.com" OR "www.yahoo.com" OR "tv.yahoo.com" OR "mail.yahoo.com")
{
print($yahoo);
}
else if($_SERVER['HTTP_HOST'] == "excite.com" OR "www.excite.com" OR "tv.excite.com" OR "weather.excite.com")
{
print($excite);
}
/// If nothing is privided we will display the below message
else
{
echo ( "Wrong Parameters" );
}
?>
Thats what i got so far.. Also, instead of writing out all sub-domains, can I use for ex. "*.yahoo.com"?? (will it still work if someone just types in "yahoo.com"?)
<?
// Just add more of these, changing the ['name'] part to match the $domains array below
$html['yahoo'] = '<b><font style="FONT-SIZE: 24pt" face="Verdana"><font color="#000080">Yahoo</font><i><font color="#ff0000">.com</font></i></font></b>';
$html['excite'] = '<b><font style="FONT-SIZE: 24pt" face="Verdana"><font color="#000080">Excite</font><i><font color="#ff0000">.com</font></i></font></b>';
// The following 2 lines were just used to test the code, hence why they are commented out
// $url = "http://mail.excite.com";
// $host = parse_url($url);
$host = parse_url($_SERVER['HTTP_HOST']);
// Add new ones like below, the first part ('yahoo') should match the HTML name above,
// the part after => should be the domain name you want to search against
$domains = array('yahoo' => 'yahoo.com', 'excite' => 'excite.com');
foreach ($domains as $site => $domain)
{
if (strpos($host['host'], $domain))
{
echo $html[$site];
}
}
?>
Reply if you need any of it explaining but I added comments for you.
Bear in mind that excite.com, yahoo.com etc are EXAMPLE domains - they will _never_ work for you in real life without you changing them to something more meaningful, because the HTTP_HOST is the name of the server your script is running on - so unless you're coding this for the yahoo.com servers, it'll never equal yahoo.com.
Maybe what you really meant was to check the referer?
OK we'll the script works only nothing comes up... and YES ofcourse, i have changed it the the proper values ;-)
When i checked for errors, this is what came up
Notice: Undefined index: host in /home/thecolla/public_html/18.php on line 20
Notice: Undefined index: host in /home/thecolla/public_html/18.php on line 20
I think everything is ok in the script except for the last