PDA

View Full Version : check for ?page=home OR domain.com



?foru
08-28-2008, 04:32 AM
The CMS system I am using utilizes query strings, and when I specified the homepage by default it shows with just domain.com It also shows the same content when you view index.php?page=home since it's the same content.

I'm using the following code to display the home rollover image to indicate a user is on that page.


<?php //home
if (isset($_GET['page']) && $_GET['page'] == 'home') {

echo "<img src=\"images/home_roll.gif\" height=\"35\" border=\"0\" />";
}

else {
echo "<a href=\"index.php?page=home\" onmouseout=\"MM_swapImgRestore()\" onmouseover=\"MM_swapImage('Image2','','images/home_roll.gif',1)\"><img src=\"images/home.gif\" name=\"Image2\" height=\"35\" border=\"0\" id=\"Image2\" /></a>";
}
?>
The above works properly when ?page=home is in the URL, but possibly "isset" can be modified to use that ALONG with domain.com since "home_roll.gif" doesn't show when it's only domain.com. Maybe using "OR" somehow in the above statement... ?page=home OR domain.com { echo this } else { echo something else } ?

Thank you for any suggestions.

?foru
08-29-2008, 03:12 AM
Ok, I found that this works somewhat. I see the logic in why it's doing it, but I'm not sure how to get around it. The following displays the "home_roll.gif" image when index.php (same as domain.com) and index.php?page=home are both accessed. The issue is now if you select another page like index.php?page=another_page since index.php is still present the same "home_roll.gif" is displayed, but I only want the page I'm on to show the rollover image.

<?php
$page =& $_SERVER['SCRIPT_NAME'];
if (isset($page) && $page == '/index.php' OR (isset($_GET['page']) && $_GET['page'] == 'home')) {

echo "<img src=\"images/home_roll.gif\" height=\"35\" border=\"0\" />";
}

else {
echo "<a href=\"index.php?page=home\" onmouseout=\"MM_swapImgRestore()\" onmouseover=\"MM_swapImage('Image2','','images/home_roll.gif',1)\"><img src=\"images/home.gif\" name=\"Image2\" height=\"35\" border=\"0\" id=\"Image2\" /></a>";
}
?>

This is sort of tricky because each menu item has this code to show the specific image according to if it's selected or not, and I don't think I can use a switch statement to show the default images such as "home.gif" if that particular page isn't selected.

Anyone have any ideas? Thank you

Master_script_maker
08-29-2008, 07:20 PM
try this:

<?php
$page = $_SERVER['SCRIPT_NAME'];

$ishome=isset($_GET['page'])?($_GET['page']=="home"?true:false):($page=="/index.php"?true:false);

if ($ishome) {
echo "<img src=\"images/home_roll.gif\" height=\"35\" border=\"0\" />";
}
else {
echo "<a href=\"index.php?page=home\" onmouseout=\"MM_swapImgRestore()\" onmouseover=\"MM_swapImage('Image2','','images/home_roll.gif',1)\"><img src=\"images/home.gif\" name=\"Image2\" height=\"35\" border=\"0\" id=\"Image2\" /></a>";
}
?>

?foru
08-29-2008, 09:20 PM
Thank you for your reply Master_script_maker

I tested your code and it seems to work like the code in my first post. It shows the home rollover image on index.php?page=home, but it didn't on index.php

I thought of some other scenarios, but they all seem to work like my code with OR in it...it shows both home and the other page highlighted.

I think your on the right track so that if it's...
index.php (show home_roll.gif)
index.php?page=home (show home_roll.gif)

any other menu item selected...
if this isn't index.php or index.php?page=home this will prove false and show home.gif

Master_script_maker
08-30-2008, 12:09 AM
i tested this out on my server so it should work:
<?php
$page = $_SERVER['SCRIPT_NAME'];

$ishome=isset($_GET['page'])?($_GET['page']=="home"?true:false):(preg_match("/index\.php/", $page)==1?true:false);

if ($ishome) {
echo "<img src=\"images/home_roll.gif\" height=\"35\" border=\"0\" />";
}
else {
echo "<a href=\"index.php?page=home\" onmouseout=\"MM_swapImgRestore()\" onmouseover=\"MM_swapImage('Image2','','images/home_roll.gif',1)\"><img src=\"images/home.gif\" name=\"Image2\" height=\"35\" border=\"0\" id=\"Image2\" /></a>";
}
?>

?foru
08-30-2008, 02:02 AM
That's perfect Master_script_maker! Worked like a charm :) I owe you one for your help...which is much appreciated.

Master_script_maker
08-30-2008, 02:28 AM
no problem. i joined this forum to help people out (and to get some :))