INCLUDE() scope issues?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
mpatters
Forum Newbie
Posts: 4
Joined: Sun Mar 07, 2004 4:53 pm

INCLUDE() scope issues?

Post 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?
d3ad1ysp0rk
Forum Donator
Posts: 1661
Joined: Mon Oct 20, 2003 8:31 pm
Location: Maine, USA

Post by d3ad1ysp0rk »

include("../init.php");
mpatters
Forum Newbie
Posts: 4
Joined: Sun Mar 07, 2004 4:53 pm

Post 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...
d3ad1ysp0rk
Forum Donator
Posts: 1661
Joined: Mon Oct 20, 2003 8:31 pm
Location: Maine, USA

Post by d3ad1ysp0rk »

oooh, sorry, didn't understand that.
mpatters
Forum Newbie
Posts: 4
Joined: Sun Mar 07, 2004 4:53 pm

Post 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. :?
User avatar
Ixplodestuff8
Forum Commoner
Posts: 60
Joined: Mon Feb 09, 2004 8:17 pm
Location: Queens, New York

Post 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' );
?>
Post Reply