Forum Moderators: coopster

Message Too Old, No Replies

Simple include question.

Calling and include from a different directory.

         

Frequent

2:42 pm on Oct 18, 2005 (gmt 0)

10+ Year Member



I'm sure this is a sickeningly simple question for anyone who has more of a clue regarding php than I. (almost everyone)

In directory "xyz" I run a php script and includes are called using %%include_1%% in the templates.

If I want to use the same include in index.php at the root am I best off using the following?

<?php
require_once('xyz/include_1.php');
?>

Freq---

jatar_k

3:50 pm on Oct 18, 2005 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



you can use the same include path from any page on the site if you use a root relative include. In your case I am guessing it would something like

require_once $_SERVER['DOCUMENT_ROOT'] . '/xyz/include_1.php';

Frequent

4:15 pm on Oct 18, 2005 (gmt 0)

10+ Year Member



I probably don't understand correctly so feel free to educate me if I am wrong.

So I would call your example once in index.php at the root and then I could include "include_1" anywhere site wide? or does your example need to be placed as a separate php file (for example "sitewide.php") in the root which in turn calls on "include_1" from the full directory path specified?

Freq---

jatar_k

4:18 pm on Oct 18, 2005 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



if all youo need is the syntax for the include in your root file, then the include you posted should work. give it a try. ;)

I may have confused the issue as I don't really know how this is set

%%include_1%%

if everything else is working, as I said, then just try the require line you posted and forget what I said.