Page 1 of 1

INCLUDE() scope issues?

Posted: Sun Mar 07, 2004 4:53 pm
by mpatters
So I'm sure this is a simple problem that lots of people have figured out, but I can't seem to find a solution anywhere, either on these forums or on the net or on PHP.net.

I have three files in three different directory locations:

/admin/clean_db.php
/classes/user.php
/init.php

I want to make clean_db.php INCLUDE() init.php, which in turn includes the user.php from the 'classes' directory.

Problem is, PHP doesn't seem to be able to find user.php when i do it this way. If I load init.php directly, it can find "classes/user.php" just fine, but if I load init.php by including it in clean_db (which is in a subdirectory), init can't find user.php

I've tried messing with init_set("include_path","path stuff here") but that doesn't seem to have much effect.

Any ideas?

Posted: Sun Mar 07, 2004 7:23 pm
by d3ad1ysp0rk
include("../init.php");

Posted: Sun Mar 07, 2004 7:38 pm
by mpatters
Yeah...that's the whole problem.

In my clean_db.php, my very first line is:

include('../init.php');

What happens is that init loads fine, but then when *it* tries to include "classes/user.php", it errors out because, as far as PHP is concerned, our current scope is apparently still inside the /admin directory, not the root...

Posted: Sun Mar 07, 2004 7:47 pm
by d3ad1ysp0rk
oooh, sorry, didn't understand that.

Posted: Sun Mar 07, 2004 8:13 pm
by mpatters
hey, no problem. it's a hard problem to explain. which makes it even more frustrating that i can't figure out a solution. :?

Posted: Sun Mar 07, 2004 9:29 pm
by Ixplodestuff8
Try somthing like this, where $path is set by the page that is opened by the browser.

/admin/clean_db.php

Code: Select all

<?php
$path = '../';

include ( $path . 'init.php' );

?>
/init.php

Code: Select all

<?php
include ( $path . 'classes/user.php' );
?>