Jump to content

[SOLVED] menu.php - I do not know a good subject


Recommended Posts

Ok I post yesterday about my menu.php


I only want to edit one page when I add a menu item or when I move a page.


Ok so I asked if I could do a include like this




because I added a selection code to my css so my menu would like this (in HTML)


  <div class="menu">
<li class="selected"><a href="index.php">Home</a></li> [b]<-Selected: Indicates the user is on this page[/b]
<li class="nonselected"><a href="_login/_members/members.php">Members</a></li> [b]<-Not Selected: Indicates the user is not on the page[/b]
<li class="nonselected"><a href="login.php">Login</a></li>
<li class="nonselected"><a href="register.php">Register</a></li>
<li class="nonselected"><a href="info/info.php">Info</a></li>


Well I got an error in my include when I did that


Warning: include(menu.php?page=login) [function.include]: failed to open stream: Invalid argument in C:\xampp\htdocs\JUNK\LAMEZ\login.php on line 56


Warning: include() [function.include]: Failed opening 'menu.php?page=login' for inclusion (include_path='.;C:\xampp\php\pear\') in C:\xampp\htdocs\JUNK\LAMEZ\login.php on line 56


So someone gave me this code


<div class="menu">
    <li class="<?php echo ($_SERVER['PHP_SELF'] == 'index.php') ? 'selected' : 'nonselected'; ?>"><a href="index.php">Home</a></li>
    <li class="<?php echo ($_SERVER['PHP_SELF'] == 'members.php') ? 'selected' : 'nonselected'; ?>"><a href="_login/_members/members.php">Members</a></li>
    <li class="<?php echo ($_SERVER['PHP_SELF'] == 'login.php') ? 'selected' : 'nonselected'; ?>"><a href="login.php">Login</a></li>
    <li class="<?php echo ($_SERVER['PHP_SELF'] == 'register.php') ? 'selected' : 'nonselected'; ?>"><a href="register.php">Register</a></li>
    <li class="<?php echo ($_SERVER['PHP_SELF'] == 'info.php') ? 'selected' : 'nonselected'; ?>"><a href="info/info.php">Info</a>


Well it did not work, at all


Any Ideas?


Was I clear enough?

Link to comment
Share on other sites

You can't pass query string parameters in an include.


Just set a variable in each page that menu.php will use to determine which link is "active".


For example, index.php:

$current_page = "home";

include_once "menu.php";



<div class="menu">
    <li class="<?php echo ($current_page == 'home') ? 'selected' : 'nonselected'; ?>"><a href="index.php">Home</a></li>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.