Enjoy unlimited access to all forum features for FREE! Optional upgrade available for extra perks.

Different logo depending on URL

Paullas

Staff member
Joined
Jul 13, 2004
Posts
5,791
Reaction score
336
Hi .

I am hoping someone can help.

I am looking for a way to show a differenrt logo depending on what URL is in the address bar

I am using a php built website and not wordpress.

thanks

Paul
 
Hi

this is what i have added to the top of my index.php file which selects which file to load when a certain domain is in the URL, what i now need is what a certain url is in the address bar to show that specific logo.


switch($_SERVER["HTTP_HOST"])
{
case "domain1.co.uk":
require("domain1.php");
exit();
break;

case "domain2.co.uk":
require("domain2.php");
exit();
break;

}
 
Hi

this is what i have added to the top of my index.php file which selects which file to load when a certain domain is in the URL, what i now need is what a certain url is in the address bar to show that specific logo.


switch($_SERVER["HTTP_HOST"])
{
case "domain1.co.uk":
require("domain1.php");
exit();
break;

case "domain2.co.uk":
require("domain2.php");
exit();
break;

}

Would this not be more efficient in an array with a simple foreach loop?
 
Look inside $_SERVER['HTTP_HOST'].

The easiest way to have all sub domains inc www redirect to pure http://domain.ext, then explode/split the result into an array and [0] will the domain name without the ext, then use result[0].jpg to display it.
 
If anyone has a guide on this that woukd be great as it is something i dont have experiwnce with.
 
Your existing code would work, just include a "$logo" variable with the require

switch($_SERVER["HTTP_HOST"])
{
case "domain1.co.uk":
require_once("domain1.php");
$logo = "domain1.jpg";
exit();
break;

case "domain2.co.uk":
require_once("domain2.php");
$logo = "domain2.jpg";
exit();
break;

}

Then where you want to use it just use it like "img src=$logo", or use a second switch at the top of the code to just handle the logo.

switch($_SERVER["HTTP_HOST"])
{
case "domain1.co.uk":
$logo = "domain1.jpg";
break;

case "domain2.co.uk":
$logo = "domain2.jpg";
break;
}

If the logo is inside domaion1.php, then put the switch inside that file for the logo.

There are loads of ways to do it, but if you already have switches probably better to use similar code.
 
A very easy way without using any loops, if's / switches. etc

My pseudo code would be.

Get last part of url or any part of it that is a unique identifier. For example https://www.mydomain.co.uk/mypage2 (mypage2)
Append ".png" to the string to make mypage2.png

Upload your given logo image and call it mypage2.png.

This should be about 4 lines of code and you will not need to add any more going forward when you add more logos / pages.

Maybe have one if statement in there to display a default image if dynamic one is not found.
 
Last edited:
Is it main domain or sub domain?

You could do this for main domain:

Code:
$url = $_SERVER['SERVER_NAME'];
// or $_SERVER['HTTP_HOST'];

$logo = "default_logo.png";

if ($url == "www.example.com")
{
    $logo = "example1.png";
}
elseif ($url == "www.example2.com")
{
    $logo = "example2.png";
}

<img src="<?php echo $logo;">">
 
If it were sub domain based you could do this:

PHP:
  $logo = "default";

  $sub_domain = explode('.', $_SERVER['HTTP_HOST']);

  $sub_domain = str_replace("https://", "", $sub_domain); // Remove the https (or http)
 
  if (count($sub_domain) > 2) {
    if ($sub_domain[0] == "www") { // if non sub eg (www.maindomain.com)
      $sub_domain = "main";
    } else {
     $sub_domain = $sub_domain[0];
    }

    $logo = $sub_domain;
  }

Usage:

Name your logo for the relevant case eg default,main,uk,fr,de etc

For every case where the rules aren't met it will display 'default', non-sub domain will show 'main' and every sub domain will display the sub domain (just add the logo extension).

HTML:
  <img src="<?php echo $logo;?>.png">
 
This sounds like you are making it way too complicated, including another php script just to show a logo is overkill.

Depending on how many logo's you are talking about would dictate the best option, for example if you are only dealing with a few logo's then use a function which contains a switch statement for each case.. However, if you have like 20+ logo's then simply use a database query which fetches the record / logo based on the domain or domain_id.
 

The Rule #1

Do not insult any other member. Be polite and do business. Thank you!

Featured Services

Sedo - it.com Premiums

IT.com

Premium Members

AucDom
UKBackorder
Be a Squirrel
Acorn Domains Merch
MariaBuy Marketplace

Domain Forum Friends

Other domain-related communities we can recommend.

Our Mods' Businesses

Perfect
Service
Laskos
*the exceptional businesses of our esteemed moderators
Top Bottom