• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 841
  • Last Modified:

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

0
redbaran28
Asked:
redbaran28
  • 3
  • 2
  • 2
  • +1
1 Solution
 
asafadisCommented:
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

0
 
redbaran28Author Commented:
I am getting the same thing. Just a square where the image should be.
0
 
Michael701Commented:
here's an idea.

Store the images for each website in a different folder
/images/portal.domain1.com/logo.gif
/images/portal.domain2.com/logo.gif

with common images in the images folder

/images/cart.gif

then in your code you can use the domain as the path for unique images

echo "<img src='/images/".$_SERVER['HTTP_HOST']."/logo.gif' />";
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
Ray PaseurCommented:
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

0
 
asafadisCommented:
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

0
 
redbaran28Author Commented:
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

0
 
Michael701Commented:
please post php code and view source and post html code.

this will help us debug
0
 
redbaran28Author Commented:
Michael70, it looks like I have yours working.

I will post back if I have trouble once I get it in the live site.
0
 
Ray PaseurCommented:
@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

0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

  • 3
  • 2
  • 2
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now