Log in

View Full Version : Need help with image display on page



rick.travel
11-25-2009, 12:45 PM
Dear all,
I was wondering if someone could hep me with the following script. I've set up this script by myself, but I don't know what I do wrong. I do not know so much about JavaScript.

What I want is the following: I am planning to combine two domains to one, but, what I want is that users calling www.rick.travel, will see the Rick.Travel logo and users which are calling www.worldofrick.nl, will see the World of Rick logo.

So, as far, I have the following code, but it doesn't work:


function showLogo()
{
if (domain=="rick.travel")
document.write('<a href="http://www.rick.travel"><img src="http://www.rick.travel/data/images/rick.png" alt="Rick.Travel" border="0" /></a>');
else
document.write('<a href="http://www.worldofrick.nl"><img src="http://data.worldofrick.nl/world/titel.png" alt="World of Rick" border="0" /></a>');
}

jscheuer1
11-25-2009, 06:16 PM
Well since I'm almost positive you have a PHP enabled server and that the filename of the page is index.php (took just a little snooping to determine that is likely the case), you could and probably should use PHP for this. That is if there will still be two domain names as shown in the browser's address bar. Will there be?

But I'm not real up on PHP, so I'd ask in the PHP section. You would probably want to test the $SERVER_NAME variable and pick the href for the link and the src and alt for the image on the basis of that. Something like:


<?php
if($SERVER_NAME == www.rick.travel || $SERVER_NAME == rick.travel)
echo '<a href="http://www.rick.travel"><img src="http://www.rick.travel/data/images/rick.png" alt="Rick.Travel" border="0" /></a>';
else
echo '<a href="http://www.worldofrick.nl"><img src="http://data.worldofrick.nl/world/titel.png" alt="World of Rick" border="0" /></a>';
?>

This would go in place of:


<a href="http://www.rick.travel"><img src="http://data.worldofrick.nl/images/ricktravel.png" alt="Rick.Travel" class="print" border="0" width="396" height="90" /></a>

and the one for the other logo on the other page.

IMPORTANT NOTE: The above is just pseudo PHP code. It may work, but if it doesn't, folks in the PHP section can correct it for you.

rick.travel
11-26-2009, 10:29 AM
Thanks!!! It worked for me!!! :D My PHP code is now the following (it's correct that rick.travel is an alias on the domain worldofrick.nl):



if (preg_match("/rick.travel/i", $_SERVER['HTTP_HOST'])) {
echo "<a href=\"http://www.rick.travel\"><img src=\"http://data.worldofrick.nl/images/ricktravel.png\" alt=\"Rick.Travel\" class=\"print\" border=\"0\" width=\"396\" height=\"90\" /></a>";
} else {
echo "<a href=\"http://www.worldofrick.nl\"><img src=\"http://data.worldofrick.nl/world/titel.png\" alt=\"World of Rick\" class=\"print\" border=\"0\" width=\"396\" height=\"90\" /></a>";
}

jscheuer1
11-26-2009, 11:10 AM
Great! It is my understanding that a preferred method of doing the same thing would be (if it works):


<?php
if (preg_match("/rick.travel/i", $_SERVER['HTTP_HOST'])) {
?>
<a href="http://www.rick.travel"><img src="http://data.worldofrick.nl/images/ricktravel.png" alt="Rick.Travel" class="print" border="0" width="396" height="90" /></a>
<?php
} else {
?>
<a href="http://www.worldofrick.nl"><img src="http://data.worldofrick.nl/world/titel.png" alt="World of Rick" class="print" border="0" width="396" height="90" /></a>
<?php
}
?>

traq
11-26-2009, 09:00 PM
I don't know that it's "preferred", exactly, but it can be easier. I generally only exit the php tags when I have a large, static block of html. For just a few lines, I prefer to use single quotes (especially for html tags, where attributes require multiple double-quotes that would otherwise need to be escaped, as above).


<?php
if (preg_match("/rick.travel/i", $_SERVER['HTTP_HOST'])) {
echo '<a href="http://www.rick.travel"><img src="http://data.worldofrick.nl/images/ricktravel.png" alt="Rick.Travel" class="print" border="0" width="396" height="90" /></a>';
} else {
echo '<a href="http://www.worldofrick.nl"><img src="http://data.worldofrick.nl/world/titel.png" alt="World of Rick" class="print" border="0" width="396" height="90" /></a>';
}
?>