Search code examples
phpincludepearrequire

Two Errors trying to include .php file: Warning: require(...) AND Fatal error: require() ... (include_path='.;C:\php\pear')


Here is the first error:

Warning: require(/hb/includes/constants.php) [function.require]: failed to open stream: No such file or directory in C:\wamp2\www\hb\includes\connection.php on line 2

And the second error that immediately follows:

Fatal error: require() [function.require]: Failed opening required '/hb/includes/constants.php' (include_path='.;C:\php\pear') in C:\wamp2\www\hb\includes\connection.php on line 2

Here is the line that it doesn't like:

require("/hb/includes/constants.php");

I did install a new version of WAMP, but I know the directories/files are fine and the code worked previously and on another server. It seems like none of my require()'s are working anymore. I tried looking around and some suggested to others that they edit their php.ini, but I don't know what directory I would point to - if you can't tell I'm pretty noobish regarding all things server related.

Any help is appreciated.


Solution

  • First of all, are your really -- really ! -- sure that the file /hb/includes/constants.php, that your are trying to include, exists ?

    Considering that the path you requested begins with a /, it looks like you're using an absolute path... that looks like an UNIX path, but you are on a Windows server...


    If it exists, and PHP still cannot include it, check :
    • that it is readable by your webserver (including the directories) -- I'm thinking about UNIX permissions
    • that there is no open_basedir restriction that would prevent PHP from accessing those files.

    BTW, having a warning and a fatal error is the behavior that's to be expected when using [`require`][2] : the warning is normal *(it comes from `include`)* ; and the fatal error is the difference between `include` and `require`.