Forum Moderators: coopster

Message Too Old, No Replies

Including Files in Different Direcories that Include Files from Teirs

         

Jacob or JaF

1:54 am on Aug 9, 2007 (gmt 0)

10+ Year Member



Okay, I made a simple AJAX shoutbox and I want to include it on all my pages. To insert the shoutbox I simply type <? include('/shoutbox/shoutbox.php');?> into my HTML page.
The problem is, that in /shoutbox/shoutbox.php I also include settings.php, functions.php, and some other files, and when I include /shoutbox/shoutbox.php into my index page, /shoutbox/shoutbox.php tries to call settings.php from the same folder that my index file is in, since I just 'included' it in index's source.

So my question is, is there any way, without using frames, to include a PHP file as it would be if you link directly to it in the address bar, but placed into another file in a different directory?

Thank you,
Jacob

Habtom

5:37 am on Aug 9, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



So my question is, is there any way, without using frames, to include a PHP file as it would be if you link directly to it in the address bar, but placed into another file in a different directory?

The question is not very clear to me. But let me tell you what I understood, and what you can do, if I misunderstand you, I apologize.

You want to include a file which is physically let's say in /fol1/fol2/fol3/file.php

Though that is the physical location, you want it to appear as if it has come from /fol1/fol2/file.php

If that is what you are looking for, I don't see the application, but you might have certain reasons, what I think you should do is, to create file.php in /fol1/fol2/file.php which "inlude"s the file.php in /fol1/fol2/fol3

This file /fol1/fol2/file.php online contains the line:

include("fol3/file.php");

I am much out of the way, let me know.

Habtom

Jacob or JaF

1:18 pm on Aug 9, 2007 (gmt 0)

10+ Year Member



I guess I wasn't clear enough...

Here's my folders and some of their contents:

site/
--index.php <? include('shoutbox/index.php');>
--functions.php
--header.php
--shoutbox/
----index.php <? require_once('functions.php'); require_once('settings.php');?>
----functions.php
----settings.php
--admin/
----index.php <? include('shoutbox/index.php');>

Now I want to include my shoutbox from index.php and admin/index.php, but then shoutbox/index.php tries to require_once settings.php, which doesn't exist, functions.php, which doesn't have the shoutbox's functions, and admin/settings.php, when I include it from the admin's index.php.

What I need to do is create the results as if I made the shoutbox in an iframe, which I don't want to do.

I hope I got this explained.

Thank you,
Jacob

WesleyC

1:28 pm on Aug 9, 2007 (gmt 0)

10+ Year Member



Within the shoutbox file, try...

include ( dirname( __FILE__ )."/functions.php" );

Jacob or JaF

1:47 pm on Aug 9, 2007 (gmt 0)

10+ Year Member



That seems to have worked, but now it says there's a fatal error because I'm redeclairing functions and, yes, I do use functions with the same name in both functions.php, should I just rename all the functions in the shoutbox, or is there another way?

Thank you,
Jacob

WesleyC

4:59 pm on Aug 9, 2007 (gmt 0)

10+ Year Member



If you want to get somewhat more advanced...

class Shoutbox
{
//all your functions in shoutbox/functions.php here
}

Then, replace your shoutbox function calls with Shoutbox::FunctionName(args).

Be warned though, this may break a few other things--do a bit of research on classes in PHP. :)