Why does this code not work on all pages?

Hello,

I have a simple website with five or six pages of which have a different header image. I’m trying to create the code to check the page’s URL and match it with the correct header image. This is the code I’m trying to use, but can’t figure out why it won’t work. I am calling this code by ‘include’ on each page:

[php]<?php

// List of page images to their root page.
$image_item = array(
“/images/home_banner.jpg” => “/home.php”,
“/images/home_banner.png” => “/energy.php”,
“/images/home_banner.png” => “/capital.php”,
“/images/technologies_banner.jpg” => “/technologies.php”,
“/images/home_banner.png” => “/properties.php”,
“/images/home_banner.png” => “/contact.php”,
);

$currenturl = $_SERVER[‘PHP_SELF’];

$currentimage = array_search($currenturl, $image_item);

echo ’

';

?>[/php]

More than likely there’s something I’m missing. Any help would be greatly appreciated.

Oh, I just did a var_dump on that array to find that it’s not storing all the data due to key values being the same. Perhaps I’m approaching this wrong?

Ok, I ended up just changing the actual image names so that the array has different keys:

[php]<?php

// List of pages images to their root page. Must use different key names (image names) for array to function properly.
$image_item = array(
“/images/home_banner.jpg” => “/home.php”,
“/images/energy_banner.jpg” => “/energy.php”,
“/images/capital_banner.jpg” => “/capital.php”,
“/images/technologies_banner.jpg” => “/technologies.php”,
“/images/properties_banner.jpg” => “/properties.php”,
“/images/contact_banner.jpg” => “/contact.php”,
);

$currenturl = $_SERVER[‘PHP_SELF’];
$currentimage = array_search($currenturl, $image_item);

echo ‘’;
?>[/php]

Sponsor our Newsletter | Privacy Policy | Terms of Service