简体   繁体   中英

PHP require/include only works once in script then fails

This isn't a problem as such, but it's bugging me and I would appreciate any help. It might be totally obvious but I can't see it.

$root_path = $_SERVER['DOCUMENT_ROOT'] 
require($root_path .'template/header.php')
require($root_path .'template/footer.php')

The script will include one or the other but not both. It will run and include the header but not the footer, if I swap them round it will load the footer first but not the header.

I've tried using include instead of require but get the same result.

It gives the error allow_url_include = 0 . I know turning this one will solve it but my question is why is it happening? Why will it include one file but not the other? Is there any way to get them to both run without turning allow_url_include on (I'm trying to be security conscious). I have PHP 5.3 and am running WAMP. Thanks in advance for your help!

看起来您正在重新定义包含文件中的$root_path

也许$root_path已在文件header.php或footer.php中更改?

There isn't anything wrong with what you've written. As the others have said, something is happening to $root_path or the script is terminating before it gets to that include.

Do a var_dump($root_path) right above the footer include. If that fires, you know it's getting to the include. If it still isn't working, do some echoes from within your footer to see if it gets inside the file.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM