How do you know the correct path to use in a PHP require_once() statement

后端 未结 9 2125
别跟我提以往
别跟我提以往 2021-01-31 22:02

As many do I have a config.php file in the root of a web app that I want to include in almost every other php file. So most of them have a line like:

require_on         


        
9条回答
  •  孤独总比滥情好
    2021-01-31 22:46

    Since require and require_once are very similar to include and include_once, all the documentation is posted under the "include" functions doc area on php.net From that page

    Files for including are first looked for in each include_path entry relative to the current working directory, and then in the directory of current script. E.g. if your include_path is libraries, current working directory is /www/, you included include/a.php and there is include "b.php" in that file, b.php is first looked in /www/libraries/ and then in /www/include/. If filename begins with ./ or ../, it is looked only in the current working directory.

    Further, you can find all the current include paths by doing a "php -i" from the command line. You can edit the include path in your php.ini file, and also via ini_set(). You can also run the php_info() function in your page to get a printout of your env vars if the CLI is inconvenient.

提交回复
热议问题