Results 1 to 7 of 7

Thread: check for ?page=home OR domain.com

  1. #1
    Join Date
    Jul 2008
    Posts
    136
    Thanks
    13
    Thanked 1 Time in 1 Post

    Default check for ?page=home OR domain.com

    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 Code:
    <?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.

  2. #2
    Join Date
    Jul 2008
    Posts
    136
    Thanks
    13
    Thanked 1 Time in 1 Post

    Default

    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 Code:
    <?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

  3. #3
    Join Date
    Jun 2007
    Posts
    543
    Thanks
    3
    Thanked 78 Times in 78 Posts
    Blog Entries
    1

    Default

    try this:
    PHP Code:
    <?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>"

    ?>
    Last edited by Master_script_maker; 08-30-2008 at 12:53 AM.
    [Jasme Library (Javascript Motion Effects)] My Site
    /\/\@ /\/\@|{
    There are 10 kinds of people in the world, those that understand binary and those that don't.

  4. #4
    Join Date
    Jul 2008
    Posts
    136
    Thanks
    13
    Thanked 1 Time in 1 Post

    Default

    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

  5. #5
    Join Date
    Jun 2007
    Posts
    543
    Thanks
    3
    Thanked 78 Times in 78 Posts
    Blog Entries
    1

    Default

    i tested this out on my server so it should work:
    PHP Code:
    <?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>"

    ?>
    [Jasme Library (Javascript Motion Effects)] My Site
    /\/\@ /\/\@|{
    There are 10 kinds of people in the world, those that understand binary and those that don't.

  6. The Following User Says Thank You to Master_script_maker For This Useful Post:

    ?foru (08-30-2008)

  7. #6
    Join Date
    Jul 2008
    Posts
    136
    Thanks
    13
    Thanked 1 Time in 1 Post

    Default

    That's perfect Master_script_maker! Worked like a charm I owe you one for your help...which is much appreciated.

  8. #7
    Join Date
    Jun 2007
    Posts
    543
    Thanks
    3
    Thanked 78 Times in 78 Posts
    Blog Entries
    1

    Default

    no problem. i joined this forum to help people out (and to get some )
    [Jasme Library (Javascript Motion Effects)] My Site
    /\/\@ /\/\@|{
    There are 10 kinds of people in the world, those that understand binary and those that don't.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •