include??

They have: 164 posts

Joined: Nov 2001

hi, i've been facing this problem all the time..

i have this:

folder forum
-global.php
-folder admin
--config.php

folder phpresume (same level with folder forum)
-index.php

in my index.php, i include global.php:

<?php
include_once(\"../forum/global.php\");
?>

i have this error:

Warning: Unable to access ./admin/config.php in /usr/local/plesk/apache/vhosts/certifyexpress.com/httpdocs/forum/global.php on line 102

Fatal error: Failed opening required './admin/config.php' (include_path='.:') in /usr/local/plesk/apache/vhosts/certifyexpress.com/httpdocs/forum/global.php on line 102
'

i felt very confused because i did this include in another page, where the situation is the same...the levels of folder is also the same...but i didnt' face any problem. but why...

pls advice!!

Mark Hensler's picture

He has: 4,048 posts

Joined: Aug 2000

When dealing with include() and require(), relative paths are always relative to the (top most) parent process.
This means that PHP is evaluating './admin/config.php' as relative to 'phpresume/index.php', and not '../forum/global.php'.

Try adding this to the PHP script before including global.php:

<?php
ini_set
(\"include_path\", ini_get(\"include_path\") . ':/usr/local/plesk/apache/vhosts/certifyexpress.com/httpdocs/forum');
?>
PHP Docs: ini_get(), ini_set(), include_path

Mark Hensler
If there is no answer on Google, then there is no question.

They have: 164 posts

Joined: Nov 2001

hmm...i've tried that...still getting the same error...

Mark Hensler's picture

He has: 4,048 posts

Joined: Aug 2000

In the error above, you have this:

Quote: Failed opening required './admin/config.php' (include_path='.:')

The include path is only '.', or the directory of the parent process. Does the include_path change after adding the ini_set() line?

Mark Hensler
If there is no answer on Google, then there is no question.

They have: 164 posts

Joined: Nov 2001

i'm getting this error after adding in..

Warning: Unable to access ./admin/config.php in /usr/local/plesk/apache/vhosts/certifyexpress.com/httpdocs/forum/global.php on line 102

Fatal error: Failed opening required './admin/config.php' (include_path='.::/usr/local/plesk/apache/vhosts/certifyexpress.com/httpdocs/forum/global.php') in /usr/local/plesk/apache/vhosts/certifyexpress.com/httpdocs/forum/ on line 102
'

They have: 164 posts

Joined: Nov 2001

errors finally gone..Smiling

this is wat i used:

<?php
chdir
($DOCUMENT_ROOT . \"/forum\");
require(
$DOCUMENT_ROOT . \"/forum/global.php\");
?>

thanks mark!!

Mark Hensler's picture

He has: 4,048 posts

Joined: Aug 2000

I think that the second error was because you have the file name in the include_path.
The inlcude_path is only suppose to indicate the directory without the trailing slash.
So, I think it saw global.php as a directory and not a file.

But anyway, you've got it working. So let's not rock the boat. Wink

Mark Hensler
If there is no answer on Google, then there is no question.

Want to join the discussion? Create an account or log in if you already have one. Joining is fast, free and painless! We’ll even whisk you back here when you’ve finished.