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?
INCLUDE() scope issues?
Moderator: General Moderators
-
d3ad1ysp0rk
- Forum Donator
- Posts: 1661
- Joined: Mon Oct 20, 2003 8:31 pm
- Location: Maine, USA
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...
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...
-
d3ad1ysp0rk
- Forum Donator
- Posts: 1661
- Joined: Mon Oct 20, 2003 8:31 pm
- Location: Maine, USA
- Ixplodestuff8
- Forum Commoner
- Posts: 60
- Joined: Mon Feb 09, 2004 8:17 pm
- Location: Queens, New York
Try somthing like this, where $path is set by the page that is opened by the browser.
/admin/clean_db.php
/init.php
/admin/clean_db.php
Code: Select all
<?php
$path = '../';
include ( $path . 'init.php' );
?>Code: Select all
<?php
include ( $path . 'classes/user.php' );
?>