Link to home
Start Free TrialLog in
Avatar of redbaran28
redbaran28

asked on

Change logo based on domain

I am trying to change the logo on our site based on what domain name they are using. I have tried this code but I just get the square where the image needs to be. Can someone help with this. PHP will work for this also if you have something that works.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
</head>
 
<script language="JavaScript" type="text/javascript">
switch ( window.location.hostname ) {
case "portal.domain1.com":
var picUrl = "images/logo1.gif"; break;
 
case "portal.domain2.com":
var picUrl = "images/logo2.gif"; break;
}
{
document.images['logo'].src = picUrl;
}
</script>
<body>
<img alt="waiting....." name="logo"  vspace="10" >
</body>
</html>

Open in new window

Avatar of asafadis
asafadis
Flag of United States of America image

At the time the script is being executed, the "img" tag hasn't been loaded yet.  Try wrapping your script in some kind of loader.

This is the simplest way to it:
<script type="text/javascript">
   window.onload = function() {
      switch ( window.location.hostname ) {
         case "portal.domain1.com":
            var picUrl = "images/logo1.gif";
            break;
 
         case "portal.domain2.com":
            var picUrl = "images/logo2.gif";
            break;
      }
 
      document.images['logo'].src = picUrl;
   }
 
}
</script>

Open in new window

Avatar of redbaran28
redbaran28

ASKER

I am getting the same thing. Just a square where the image should be.
ASKER CERTIFIED SOLUTION
Avatar of Michael701
Michael701
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
I like to have a "config.php" script that I include at the top of all my regular page scripts.  The config handles all the common stuff - session, data base connections, define statements, local classes and functions, etc.  You could initialize the correct image link in the config script with something like this...

Best regards, ~Ray
<?php 
 
// THESE STATEMENTS IN THE CONFIG SCRIPT
$image_link = '/default.png';
if (eregi('\.ABC\.', $_SERVER["HTTP_HOST"])) { $image_link = '/images/abc.png'; }
if (eregi('\.DEF\.', $_SERVER["HTTP_HOST"])) { $image_link = '/images/def.png'; }
if (eregi('\.XYZ\.', $_SERVER["HTTP_HOST"])) { $image_link = '/images/xyz.png'; }
 
// THIS IN THE MAIN SCRIPTS
echo "<img src=\"$image_link\" />\n";

Open in new window

Try this PHP solution:
<?php
switch($_SERVER['HTTP_HOST']) {
   case "portal.domain1.com":
      $picUrl = "images/logo1.gif";
      break;
 
   case "portal.domain2.com":
      $picUrl = "images/logo2.gif";
      break;
}
 
echo "<img src='/images/$picURL.gif' />";
?>

Open in new window

Thanks everyone for there posts. I have tried each one but have not had any luck. From what I can see the _SERVER['HTTP_HOST'] request is not populating in the path.

asafadis, If I look at the path for the missing image I get http://portal.domain1.com/images/.gif

Ray, I will only get the default image.

Michael701, I get a blank screen.

Thanks

please post php code and view source and post html code.

this will help us debug
Michael70, it looks like I have yours working.

I will post back if I have trouble once I get it in the live site.
@redbaran28: You can use this script to see what $_SERVER and other super-global variables are present in PHP.  Not all implementations are the same, but I have found $_SERVER to be accurate most of the time.

Beware of things like "safe mode" and other oddities in PHP support.  It can create some strange programming anomalies, and occasionally cause scripts to misbehave.

Good luck with it, ~Ray
<?php phpinfo(); ?>

Open in new window