简体   繁体   中英

PHP include problem

Index.php -> includes init.php init.php -> includes config.php config.php -> contains the configuration

Not the problem is that I am able to access content from config.php into index.php but when I trying to access data from init.php or index.php into config.php it is not happening.

If i put echo "i am text" in config.php and run index.php then nothing is displayed on the screen but when i run "echo $item_from_config_file" then it does output data as set in config.php

Please help and suggest a way of getting around this problem as it is driving me mad.

Yeah, the config.php file doesn't know anything about the init.php file, it's just being put inside it.

So, there's no way for config.php to directly read from init.php if it's being included.

I'd suggest integrating config.php into init.php.

Maybe the order isn't okay. Make sure you include all the files first then try to access their variables.

config.php:

$variable = "foo";

init.php:

include("config.php");
$variable.= " bar";

index.php:

include("init.php");
echo $variable;

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