4

I got a problem with the set_include_path, I read a lot of messages on that problem but none works for me. I'm on Debian and my root directory would be set to /home/project/

So I tried these 4 different things :

ini_set("include_path", '/home/project');
ini_set("include_path", '.:/home/project');
set_include_path('.:/home/project');
set_include_path('/home/project');
set_include_path(get_include_path().PATH_SEPARATOR.'/home/project');

But none works... when I do echo get_include_path(); it seems good each time.

But the 4th method works perfectly with WAMP on my computer.

Error message on ALL of these :

Warning: include(/config/config.php) [function.include]: failed to open stream: No such file or directory in /home/project/web/www.project.com/index.php on line 3

Warning: include() [function.include]: Failed opening '/config/config.php' for inclusion (include_path='.:/usr/share/php:/usr/share/pear:/home/project') in /home/project/web/www.project.com/index.php on line 3

3 Answers 3

6

Try to make use of the PATH_SEPARATOR constant as it is done in the documentation.

set_include_path(get_include_path() . PATH_SEPARATOR . $path);

Maybe it varies on the system you're deploying your application to..

UPDATE: The include path seems to be fine, but the problem is something different..

You shouldn't be including:

require '/config/config.php'

but

require 'config/config.php'

So drop the leading slash and it should work.

Sign up to request clarification or add additional context in comments.

4 Comments

Could you post the error your getting when it tries to include the file? It usually prints out the include path that was used as well. Did it change?
Sorry I needed to leave work, This works but if I include a file in the same folder what happens ?
It always takes the first one in the include path.
Ah I just learned something that I didn't know... It tests all of the path in the get_include_path() from the left to the right. Good it's ok for me :-) Thanks
1

Set using this: set_include_path(get_include_path().PATH_SEPARATOR.'/path/');, this don't remove existing include_path, setted by others scripts, and add default system path separator.

Comments

1

The path separator may differ.

set_include_path(implode(PATH_SEPARATOR, array(
    '.',
    '/home/project',
    get_include_path()
));

With this you get the current include path appended to the ones you added on your own and the correct path separator for each system.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.