Functions stop working when file included with root path (leading slash)

前端 未结 3 1223
野趣味
野趣味 2020-12-18 14:34

My PHP files in my root directory INCLUDE header.php. Header.php INCLUDEs functions.php. I\'m adding new pages in a subdirectory, so I added leading slashes to all my links

3条回答
  •  梦毁少年i
    2020-12-18 15:04

    Include and Require literally pull the code into the executing file, so one thing to watch out for is that the files in a subdirectory are running from the working directory.

    Example:

             |-templates-|-header.php
    Docroot--|
             |-inc-|-functions.php
             |
             |-index.php
    

    Index.php

    
    

    template/header.php

    
    

    because the header.php code is being executed from the docroot due to the include.

提交回复
热议问题