开发者

PHP require/include only works once in script then fails

开发者 https://www.devze.com 2022-12-29 21:37 出处:网络
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 c开发者_如何学Can\'t see it.

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 c开发者_如何学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!


Maybe $root_path is changed in the file header.php or footer.php ?


Looks like you're redefining $root_path in the included file.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消