Trouble Including Needed Files

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
M$G
Forum Newbie
Posts: 1
Joined: Mon Jun 16, 2003 1:27 pm

Trouble Including Needed Files

Post by M$G »

Hi
I've created this news script that I will eventualy relese publicly and have everything working greate however I am unable to include a file needed for one of the files that displays the news. For example I need to inclue a news.php files but in that file I need a config.php file. Here is the code for the news display includes:

Code: Select all

<?php
include "admin/config.php";

.... and so forth
?>
on my home page i need to include the newsdisp.php file by using

Code: Select all

<?php
include "/home/micro/public_html/projects/Mnews/mnewsDisplay.php";
?>
this leads to the problem... the config.php file is not included in the display file when I try to include it. It works great other wise.
User avatar
daven
Forum Contributor
Posts: 332
Joined: Tue Dec 17, 2002 1:29 pm
Location: Gaithersburg, MD
Contact:

Post by daven »

include "admin/config.php" looks in your standard include directory (such as /etc/php4/includes) for the admin folder. Therefore, php is not finding the proper file.

To use another location, you must either hard-code it (ex: "/path/to/admin/config.php") or use relative paths (ex: "./admin/config.php"). Using "./" starts looking in the current directory, and "../" starts looking in the script's parent directory.
User avatar
delorian
Forum Contributor
Posts: 223
Joined: Sun May 04, 2003 5:20 pm
Location: Olsztyn, Poland

Post by delorian »

You should include files giving a path from the highest file in the include tree:

e.g.

Code: Select all

/*
folder tree:
 index.php
 pages/news.php
 admin/config.php
*/

// so in index.php you have

include("pages/news.php");

// and in news.php you have

include("admin/config.php");
The all paths in news.php and config.php must be write in the way that they were in the index.php.
Post Reply