Include paths

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
Michael_C
Forum Commoner
Posts: 51
Joined: Thu Feb 09, 2006 4:32 pm
Location: California

Include paths

Post by Michael_C »

I believe I'm having a "path" problem. I'm altering the Advanced Poll app which has the following (partial) directory structure:
poll
. admin
. include

I'm not getting any error messages, nor any output

My first approach gave me errors - path errors in common.inc.php(in admin folder). As an example, I modified the path references in common.inc.php from:

Code: Select all

require "./include/config.inc.php";
To:

Code: Select all

$include_path = dirname(__FILE__);
if ($include_path == "/") {
    $include_path = ".";
}

require $include_path."/../include/config.inc.php";
The errors were resolved, however, this didn't provide any output

I then added the set_include_path() entry in index.php
The first 7 lines in index.php has:

Code: Select all

set_include_path('./include');
$include_path = dirname(__FILE__);
if ($include_path == "/") {
    $include_path = ".";
}
require $include_path . "/admin/common.inc.php" ;
echo("Reached index") ;
Still no output.

Is there a way to tell what has been executed, and what hasn't? like, any logging or trace facility? I know I can use echo() statements (or the like?). I imagine some of the changes in common.inc.php can be backed out since adding the set_include_path() in index.php, but would think

The index.php file I have created in "poll" folder is to display a list of all active polls, with either a "vote", or "display status" button depending on whether the user has already voted on a poll. The look of the page was to parallel the index.php in the "admin" folder.

Any and all help would be appreciated.

Michael
User avatar
$var
Forum Contributor
Posts: 317
Joined: Thu Aug 18, 2005 8:30 pm
Location: Toronto

Post by $var »

would trying this maybe work:

include ('./include/config.inc.php');
or
include ('http://www.blablablah.com/include/config.inc.php');
Michael_C
Forum Commoner
Posts: 51
Joined: Thu Feb 09, 2006 4:32 pm
Location: California

Post by Michael_C »

$var wrote:would trying this maybe work:

include ('./include/config.inc.php');
or
include ('http://www.blablablah.com/include/config.inc.php');
Thanks for the response.

The original code was

Code: Select all

require "./include/config.inc.php";
which caused errors trying to open the file stream.

By concatenating dirname(__FILE__) with include/config.ini.php it is essentially doing an absolute path equivalent to 'http://www.blablablah.com/include/config.inc.php'

Michael
Michael_C
Forum Commoner
Posts: 51
Joined: Thu Feb 09, 2006 4:32 pm
Location: California

Post by Michael_C »

It wasn't a path issue. I hadn't seen code at the end of common.inc.php - I had assumed it was exclusively setting up a bunch of global arrays - it also checks if correctly logged in - if not, it exits

Michael
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Michael_C wrote:By concatenating dirname(__FILE__) with include/config.ini.php it is essentially doing an absolute path equivalent to 'http://www.blablablah.com/include/config.inc.php'
not exactly true. The path returned would be a local file system path, not a URL. So it may in fact be very different from the URL..
Post Reply