How to use a PHP includes across multiple directories/sub directories with relative paths

前端 未结 5 1934
旧时难觅i
旧时难觅i 2020-12-03 18:06

I\'m having difficulty with paths in a cms system I\'m attempting to build, I\'ve basically got a folder with my header.php and footer.php files inside.

These are in

5条回答
  •  抹茶落季
    2020-12-03 19:10

    I prefer setting the environment variables (in Apache, using .htaccess or the .conf). This way you can move all your files freely anywhere in webroot and it will have access to those variables.

    SetEnv lib /library/folder/
    SetEnv public /my/web/root/
    SetEnv environ DEVELOPMENT
    

    Also you can use the variable named 'environ' mentioned in the above .htaccess snippet to include a server specific file as config file in all of your scripts and set various variables there.

    require_once getenv('lib')."Configs/Config_".getenv('environ').".php";
    

    Enjoy your freedom!

提交回复
热议问题