Lamez Posted September 25, 2007 Share Posted September 25, 2007 I want to include my menu on each page. My menu tells you what page you are on by using a selection code I added to my CSS. Instead of havening separate menu codes on each page I want to have them on all one page in case I add a menu item or move a page, I can just edit one page. So I tried to do this in my menu.php <?php $getlink = $_GET["page"]; if ($getlink == "index") { print <<<IND <div class="menu"> <ul> <li class="selected"><a href="index.php">Home</a></li> <li class="nonselected"><a href="_login/_members/members.php">Members</a></li> <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> </ul> </div> IND; } elseif ($getlink == "login") { print <<<LOG <div class="menu"> <ul> <li class="nonselected"><a href="index.php">Home</a></li> <li class="nonselected"><a href="_login/_members/members.php">Members</a></li> <li class="selected"><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> </ul> </div> LOG; } elseif ($getlink == "register") { print <<<LOG <div class="menu"> <ul> <li class="nonselected"><a href="index.php">Home</a></li> <li class="nonselected"><a href="_login/_members/members.php">Members</a></li> <li class="nonselected"><a href="login.php">Login</a></li> <li class="selected"><a href="register.php">Register</a></li> <li class="nonselected"><a href="info/info.php">Info</a> </ul> </div> LOG; } else { echo "Menu?"; } ?> So in my index.php I would put <?PHP include ("menu.php?page=index"); ?> or instead of index I would put login, and so on. Well I get this error Warning: include(/menu.php?page=index) [function.include]: failed to open stream: Invalid argument in C:\xampp\htdocs\JUNK\LAMEZ\index.php on line 13 Warning: include() [function.include]: Failed opening '/menu.php?page=index' for inclusion (include_path='.;C:\xampp\php\pear\') in C:\xampp\htdocs\JUNK\LAMEZ\index.php on line 13 How should I go about this? What am I doing Wrong? BTW I know I am missing Tags in my menu.php Quote Link to comment https://forums.phpfreaks.com/topic/70571-solved-question-about-includes/ Share on other sites More sharing options...
trq Posted September 25, 2007 Share Posted September 25, 2007 Just make menu.php look like... <div class="menu"> <ul> <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> </ul> </div> then use... include 'menu.php'; Quote Link to comment https://forums.phpfreaks.com/topic/70571-solved-question-about-includes/#findComment-354613 Share on other sites More sharing options...
Lamez Posted September 25, 2007 Author Share Posted September 25, 2007 You got them mixed up Thanks Though here is what I changed <div class="menu"> <ul> <li class="<?php echo ($_SERVER['PHP_SELF'] == 'index.php') ? 'nonselected' : 'selected'; ?>"><a href="index.php">Home</a></li> <li class="<?php echo ($_SERVER['PHP_SELF'] == 'members.php') ? 'nonselected' : 'selected'; ?>"><a href="_login/_members/members.php">Members</a></li> <li class="<?php echo ($_SERVER['PHP_SELF'] == 'login.php') ? 'nonselected' : 'selected'; ?>"><a href="login.php">Login</a></li> <li class="<?php echo ($_SERVER['PHP_SELF'] == 'register.php') ? 'nonselected' : 'selected'; ?>"><a href="register.php">Register</a></li> <li class="<?php echo ($_SERVER['PHP_SELF'] == 'info.php') ? 'nonselected' : 'selected'; ?>"><a href="info/info.php">Info</a> </ul> </div> Quote Link to comment https://forums.phpfreaks.com/topic/70571-solved-question-about-includes/#findComment-354626 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.