CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Jan 2016
    Posts
    1

    Change logo based on incoming domain

    I am posting here for generic coding support rather than WordPress. I originally posted this on the WordPress Development Stack Exchange and was supported until it was no longer a WordPress related matter.

    The agency I work for are trying to get a client's logo to change based upon the incoming URL.

    Now, we have 4 different URLs, therefore 4 different logos.

    Currently, we are using an if/else statement, and the default logo is being bought through to the header.

    The if/else statement we are using is as follows:

    PHP Code:
    <?php 
    if(!empty($image)) {
    echo 
    '<h1>WEBSITE_NAME_HERE</h1>';
    }
    else {
    echo 
    '<img src="'.logoSwap().'" alt="Localised Logo">';
    }
    ?>
    The problem now lies with the logo not actually changing.

    We are using a switch/case statement to actually specify the image paths and the incoming domains, and in order for the logoSwap() function to actually be declared:

    PHP Code:
    <?php
    function logoSwap(){
    switch(
    $_SERVER['HTTP_HOST']) {
    case 
    'WEBSITE_URL_HERE.com':
    $logo "WEBSITE_URL_HERE/wp-content/uploads/2016/01/logo-red.png";
    break;
    case 
    'www.WEBSITE_URL_HERE.com':
    $logo "WEBSITE_URL_HERE/wp-content/uploads/2016/01/logo-red.png";
    break;
    case 
    'WEBSITE_URL_HERE.co.uk':
    $logo "WEBSITE_URL_HERE/wp-content/uploads/2015/09/logo.png";
    break;
    case 
    'www.WEBSITE_URL_HERE.co.uk':
    $logo "WEBSITE_URL_HERE/wp-content/uploads/2015/09/logo.png";
    break;
    default:
    $logo "WEBSITE_URL_HERE/wp-content/uploads/2015/09/logo.png";
    break;
    }
    return 
    $logo;
    }
    ?>
    The .com domain is using a 301 redirect which is pulling it directly to the .co.uk domain, however the logo isn't changing when accessed from the .com domain. Could it simply be the fact that it is coming in via a 301 redirect?

    For example, I will type in mywebsite.com and I will get redirected to mywebsite.co.uk, however it displays the same logo on both.

    It has been suggested to me to set a cookie (i.e. com=1) on the redirect, and then simply do the logoSwap() function as a simple "if cookie set, show red, else show normal" code.

    Unfortunately, I don't quite know how I'm going to do this, so this is where I need your help.

    Any help would be much appreciated.

  2. #2
    Join Date
    May 2002
    Posts
    10,943

    Re: Change logo based on incoming domain

    Is all of this on the same host? Or are the .com/.co.uk on separate hosts? If they are on the same host, then perhaps changing your 301 redirect parameters to mask instead of full redirect might work. Not exactly sure though.

    If they are on separate hosts, you're sunk either way because cookies or even sessions are not host transferrable.
    If the post was helpful...Rate it! Remember to use [code] or [php] tags.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured