...

View Full Version : Includes - how to link to them?



bigbadroo
02-14-2008, 09:18 AM
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

Andrew Johnson
02-14-2008, 09:22 AM
Well you should be aware you need to specify a protocol...

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

bigbadroo
02-14-2008, 09:44 AM
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

Andrew Johnson
02-14-2008, 11:31 AM
Green = good, red = bad

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

ahallicks
02-14-2008, 12:09 PM
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

nikos101
02-14-2008, 12:19 PM
Or your could buy Dreamweaver and use its templating functionality

VIPStephan
02-14-2008, 03:36 PM
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…

_Aerospace_Eng_
02-14-2008, 03:39 PM
I would do something like this

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

bigbadroo
02-17-2008, 04:15 AM
Thanks VIP - "../../../navigation.php" did the trick.

Apologies for posting this here instead of PHP.

Shaun



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum