Jump to content

Recommended Posts

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

Link to comment
https://forums.phpfreaks.com/topic/70571-solved-question-about-includes/
Share on other sites

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';

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>

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.

Guest
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.