Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 9 of 9
  1. #1
    New Coder
    Join Date
    Jan 2008
    Posts
    61
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Includes - how to link to them?

    Hi

    I have an include called navigation.php for my menu

    <?php include ("navigation.php"); ?>

    Ideally I'd just like to have one for the whole website, but I'm not sure how to make webpages futher into the directory tree access it. I've can put "..navigation.php" , and that works when the page is one page deeper than the include, but how do you do it when the page is four or five idrectoried deep? I tried doing this:

    <?php include ("www.mywebsite.com/navigation.php"); ?> , but it didn't work.

    What is the correct way of doing this so that I don't have to have a navigation.php page at each directory level?

    Cheers

    Shaun

  • #2
    Banned
    Join Date
    Feb 2008
    Location
    Winnipeg, Canada
    Posts
    396
    Thanks
    0
    Thanked 29 Times in 29 Posts
    Well you should be aware you need to specify a protocol...

    http://www.website.com/navigation.php
    www.website.com/navigation.php

  • #3
    New Coder
    Join Date
    Jan 2008
    Posts
    61
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Hi Andrew

    Thanks for the info. I'm kind of new to includes.

    I'm not sure I understand what I have done wrong - you say to specify a protocol, and then have two web addresses. i tried putting in the full weblink, but it didn't work. Have I misunderstood what you meant? can you please explain a little more for me?

    Cheers

    Shaun

  • #4
    Banned
    Join Date
    Feb 2008
    Location
    Winnipeg, Canada
    Posts
    396
    Thanks
    0
    Thanked 29 Times in 29 Posts
    Green = good, red = bad

    <?php include ("http://www.mywebsite.com/navigation.php"); ?> will successfully include the file.

  • #5
    Senior Coder ahallicks's Avatar
    Join Date
    May 2006
    Location
    Lancaster, UK
    Posts
    1,134
    Thanks
    1
    Thanked 57 Times in 55 Posts
    Or, if you are in a directory above that navigation.php file you would do something like:

    <?php include ("../navigation.php"); ?>

    This steps up one directory into the one before. Of course, the other way to do this would be to have one page with all of your HTML, minus the content, then include the content so you keep everything else in one place rather than adding bits and pieces here and there
    "write it for FireFox then hack it for IE."
    Quote Originally Posted by Mhtml View Post
    Domains are like women - all the good ones are taken unless you want one from some foreign country.
    Reputation is your friend

    Development & SEO Tools

  • #6
    Senior Coder nikos101's Avatar
    Join Date
    Dec 2006
    Location
    London
    Posts
    1,007
    Thanks
    59
    Thanked 10 Times in 10 Posts
    Or your could buy Dreamweaver and use its templating functionality


  • #7
    The fat guy next door VIPStephan's Avatar
    Join Date
    Jan 2006
    Location
    Halle (Saale), Germany
    Posts
    8,677
    Thanks
    6
    Thanked 1,008 Times in 981 Posts
    Quote Originally Posted by bigbadroo View Post
    What is the correct way of doing this so that I don't have to have a navigation.php page at each directory level?
    • Same directory: <?php include ("navigation.php"); ?>
    • One level below: <?php include ("dir/navigation.php"); ?>
    • Two levels below: <?php include ("dir/subdir/navigation.php"); ?>
    • One level above: <?php include ("../navigation.php"); ?>
    • Two levels above: <?php include ("../../navigation.php"); ?>


    You get the point…

  • Users who have thanked VIPStephan for this post:

    Barking-Gecko (02-17-2008)

  • #8
    Supreme Master coder! _Aerospace_Eng_'s Avatar
    Join Date
    Dec 2004
    Location
    In a place far, far away...
    Posts
    19,291
    Thanks
    2
    Thanked 1,043 Times in 1,019 Posts
    I would do something like this
    PHP Code:
    <?php include_once($_SERVER['DOCUMENT_ROOT']."/navigation.php"); ?>
    Also this is a php question so why did you post it here?

    You may want to echo out $_SERVER['DOCUMENT_ROOT'] just to make sure that it is the actual root of your site.
    ||||If you are getting paid to do a job, don't ask for help on it!||||

  • #9
    New Coder
    Join Date
    Jan 2008
    Posts
    61
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thanks VIP - "../../../navigation.php" did the trick.

    Apologies for posting this here instead of PHP.

    Shaun


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •