Change Web Image based on incoming url

Joined
Jun 4, 2006
Messages
33
Hey web gurus, I was wondering if someone could help me with some code:

What I need
In my header.php I currently call a jpg image as the header. No big deal. What I want to be able to do is change that one image based off whether the incoming url is xxxxx.com or xxxxxxx.com (it could only be 2 different domains.)

Any help would be fantastic. Thank you!
 
It this code I would put in my .htaccess file? Can you give me an example beyond the link? Thank you!
 
what would probably be more effective would be along the lines of
Code:
$imgSrc = 'some/default/image.jpg';
if ('a.com' == $_SERVER['SERVER_NAME']) {
    $imgSrc = 'a.com.jpg';
} else if ('b.com' == $_SERVER['SERVER_NAME']) {
    $imgSrc = 'b.com.jpg';
}

echo "<img src=\"$imgSrc\" alt=\"some alt text\" />";
could maybe try $_SERVER['HTTP_HOST'] instead, but that relies on the client sending the host header with the request.
 
Last edited:
could maybe try $_SERVER['HTTP_HOST'] instead, but that relies on the client sending the host header with the request.

That's what I meant to say. I can't imagine any clients not sending the host header these days - name-based virtual hosting is just far too prevalent. Neglecting that would break a big chunk of the internet.
 
Back
Top