Forum Moderators: coopster
Example
<?if(strpos($_SERVER['PHP_SELF'],"/products/")!==false){?>
<img src="img/image1.gif" alt="" width="160" height="100" border="0">
<?}?>
<?if(strpos($_SERVER['PHP_SELF'],"/services/")!==false){?>
<img src="img/image2.gif" alt="" width="160" height="100" border="0">
<?}?>
<?if(strpos($_SERVER['PHP_SELF'],"/contact/")!==false){?>
<img src="img/image3.gif" alt="" width="160" height="100" border="0">
<?}?>
<?else>
<img src="img/image4.gif" alt="" width="160" height="100" border="0">
<?}?>
It's the last part that doesn't fly...
Thanks!
~ John
Just a guess
You're halfway there :)
<?else> is missing the open curly + closing question mark.
John - Are the second and third ifs meant to be elseifs? Also, you could combine the closing bracket with the next if to cut down on the number of php tags you're using. It might make the code a bit more readable. And it's best if you can to avoid using short tags (with 'php' written) cause they're not always supported.
<?php if(strpos($_SERVER['PHP_SELF'],"/products/")!==false){?>
<img src="img/image1.gif" alt="" width="160" height="100" border="0">
<?php }elseif(strpos($_SERVER['PHP_SELF'],"/services/")!==false){?>
<img src="img/image2.gif" alt="" width="160" height="100" border="0">
Why to make your life tough when you can write much simpler code than that, it will also help you debug easier. Personally if i wrote that i would write
<?php
if(strpos($_SERVER['PHP_SELF'],"/products/")!==false)
{
echo '<img src="img/image1.gif" alt="" width="160" height="100" border="0">';
}
elseif(strpos($_SERVER['PHP_SELF'],"/services/")!==false)
{
echo '<img src="img/image2.gif" alt="" width="160" height="100" border="0">';
}
elseif(strpos($_SERVER['PHP_SELF'],"/contact/")!==false)
{
echo '<img src="img/image3.gif" alt="" width="160" height="100" border="0">';
}
else
{
echo '<img src="img/image4.gif" alt="" width="160" height="100" border="0">';
}
?>
Hope it helps