Jump to content

Can I use an includes to call this menu?


roldahayes

Recommended Posts

Hi the code below calls a menu at the top of my pages.  My question is, can I assign $topnav to a PHP includes?

 

I would like it to display menu.php in the space that $topNav is displayed on.

 

I hope that all makes sense!

 

 

$topNav  = '<div id="topnav" class="topnav">  <a href="login.php" class="signin"><span>Sign in</span></a><a href="./register.php" class="register"><span>Register</span></a></div>
                
                <form method="post" id="signin" action="./index.php">
                  <label for="username">Username or email</label>
                  <input id="username" name="username" value="" title="username" tabindex="4" type="text">
              <p>
                <label for="password">Password</label>
                <input id="password" name="password" value="" title="password" tabindex="5" type="password">
             </p>
             <p class="remember">
               <input id="signin_submit" value="Sign in" tabindex="6" type="submit">
               <input id="remember" name="remember_me" value="1" tabindex="7" type="checkbox">
               <label for="remember">Remember me</label>
             </p>
             <p class="forgot"> <a href="./forgotten.php" id="resend_password_link">Forgot your password?</a> </p>
             <p class="forgot-username"> <a href="./forgotten.php" id="forgot_username_link" title="If you remember your password, try logging in with your email" href="#">Forgot your username?</a></p>
            </form>
            </fieldset>
			';      
}

Link to comment
Share on other sites

You really shouldn't have all that HTML inside a PHP variable - I'm surprised it actually works!

 

You've got two options:

 

1. Put all that HTML inside a text file and simply include that text file wherever you want it to appear, e.g.

 

include("menu_file.inc");

 

2. Create a new PHP file, create a function inside that file called top_nav() to contain all that HTML, then include that file at the top of your pages and use the following code to call that function wherever you want it to appear, e.g.

 

top_nav();

 

If you're not already familiar with PHP functions, you should read up about them.

Personally I would create a function for this, but because that code doesn't include any PHP, it would probably be simpler for you to use the text file option.

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.

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.