PHP Include Menu

Discussion in 'Web Design and Development' started by JackT06, Mar 20, 2011.

  1. JackT06 macrumors 6502

    JackT06

    Joined:
    Jul 24, 2009
    #1
    Hello,

    My problem is that for my menus i use the PHP include function, but i have just made a new directory to start making my blog inside, and my php include function isn't working, because my pages are in the previous directory, how can i get around it?

    Below is my code:
    HTML
    Code:
    <div id="menu">
    <?php include("../Nav_Bar.php"); ?>
    </div>
    <!-- end #menu -->
    PHP:
    <link href="style.css" rel="stylesheet" type="text/css" media="screen" />
    <
    html>
    <
    div id="menu">
    <
    ul>
     
        <
    li><a href="index.html">Home</a></li>
        <
    li><a href="Blog.html">Blog</a></li>
        <
    li><a href="Gallery.html">Gallery</a></li>
        <
    li><a href="Documents.html">Documents</a></li>
        <
    li><a href="DoingDofE.html">Doing DofE</a></li>
        <
    li><a href="DofE_News.html">DofE News</a></li>
        <
    li><a href="ContactUs.html">Contact Us</a></li>
    </
    ul>
    </
    div>
     
  2. Dunmail macrumors regular

    Joined:
    Mar 27, 2009
    Location:
    Skipton, UK
    #2
    lookup the ini_set function in the PHP manual. Better is if your ISP allows you to use a .htaccess file.
     
  3. harpster macrumors regular

    Joined:
    Jan 26, 2010
    #3
    If you are having problems with referencing the path to your include file you can do something like this.

    PHP:
    include ($_SERVER['DOCUMENT_ROOT'] . '/crg/admin_header.inc.php');
    That way you are always starting from your root folder and then just tack on the path to your include file.
     
  4. jsm4182 macrumors 6502

    Joined:
    Apr 3, 2006
    Location:
    Beacon, NY
    #4
    You could simply start all the address with a slash which sets it at the root directory. Instead of href="index.html" use href="/index.html" and no matter which directory you are in at the time it will bring you to the same address.
     
  5. elppa macrumors 68040

    elppa

    Joined:
    Nov 26, 2003
    #5
    I'd agree with this. Simple and will work for all cases.
     

Share This Page