Script change web page title based on domain name

Is there an easy way to change url file based on domain name?

I have acme.com and acme.co.uk domains, which require a different header, but otherwise identical content. Instead of managing two sets of files and a CMS, is there a JS / php script or other method for dynamically changing the graphic URL of the header based on which domain name it has access to? The site is basic XHTML and CSS.

+4
source share
3 answers

With php

Use $ _SERVER ['HTTP_HOST'] to get your domain, and then execute the switch statement to change the image variable.

<?php switch($_SERVER['HTTP_HOST']) { case 'acme.com': case 'www.acme.com': $image = "acmecom.jpg" break; case 'acme.co.uk': case 'www.acme.co.uk': $image = "acmecouk.jpg" break; default: $image = "default.jpg" break; } ?> 

If you use www before acme.com, you need to change the address from “acme.com” to “www.acme.com”. Same for .co.uk.

In your header image, you then repeat the image path as follows:

<img src="path/to/folder<?php echo $image;?>" alt="header-image" />

+6
source

Because I can't stand Tim's coding style ...

 <? $host = preg_replace('~^www\.~','',$_SERVER['HTTP_HOST']); $headerpic = basename($host).".jpg"; if (!is_readable($_SERVER['DOCUMENT_ROOT'])."/images/header/".$filename) { $headerpic = "default.jpg" } ?> <img src="/images/header/<?=$headerpic?>"> 
+2
source

You can do this with PHP using an if .

http://php.net/manual/en/reserved.variables.server.php $ _SERVER variable is useful here.

And then you just need to print / return the desired path to the image.

I can also give you a complete example, but try it yourself, it's worth it.

+1
source

All Articles