Xeoncross Posted August 28, 2007 Share Posted August 28, 2007 I have a file in an admin area that is not getting access to the $site_config variables in a config file. Here is what my simplified file system looks like: config.php index.php /lang/en.php /admin/index.php When I run index.php in the root dir it reads config.php and finds the file "en.php" in the language folder. Because config has a value called "$site_config["lang"]" which is = "en" so config includes "en.php"; Now when I access /admin/index.php it also reads the config file but it tries to find "/lang/.php" because the variable "$site_config["lang"]" appears to be empty. Here is what /admin/index.php looks like: require("../config.php"); require("../lang/". $site_config["lang"]. '.php'); Anyone know what might be wrong? Why is $site_config["lang"] set to "en" for index.php and not for /admin/index.php? Link to comment https://forums.phpfreaks.com/topic/67077-solved-includes-not-sharing-variables/ Share on other sites More sharing options...
lemmin Posted August 28, 2007 Share Posted August 28, 2007 You should post more code on how you are including each file and where. Link to comment https://forums.phpfreaks.com/topic/67077-solved-includes-not-sharing-variables/#findComment-336387 Share on other sites More sharing options...
Xeoncross Posted August 28, 2007 Author Share Posted August 28, 2007 How does php read files? like take the "include" logic bellow. Each of the ">" means that it is requiring the following file: index > functions > config > site_config > lang Would php get to the "config" page run it and then go back to "functions" and include "lang" before it included "site_config"? Link to comment https://forums.phpfreaks.com/topic/67077-solved-includes-not-sharing-variables/#findComment-336481 Share on other sites More sharing options...
Jessica Posted August 28, 2007 Share Posted August 28, 2007 What? Are you sure config is actually included? And that site_config is? Link to comment https://forums.phpfreaks.com/topic/67077-solved-includes-not-sharing-variables/#findComment-336485 Share on other sites More sharing options...
lemmin Posted August 28, 2007 Share Posted August 28, 2007 I think if you posted some code someone would catch something wrong. Link to comment https://forums.phpfreaks.com/topic/67077-solved-includes-not-sharing-variables/#findComment-336495 Share on other sites More sharing options...
Xeoncross Posted August 28, 2007 Author Share Posted August 28, 2007 ok, I found the problem - in config.php there is a the code like this: <?php $file = 'sites/site_config.php'; if(file_exists($file)) { require_once($file); } ?> Somehow that code was true on the "/index.php" file but not on "/admin/index.php". Therefore the $site_config array was included on "/index.php" but not on "/admin/index.php". aghhhh.... Link to comment https://forums.phpfreaks.com/topic/67077-solved-includes-not-sharing-variables/#findComment-336503 Share on other sites More sharing options...
Jessica Posted August 28, 2007 Share Posted August 28, 2007 Well, the path is not the same anymore. On that page the sites folder exists in the same directory as index.php. In the admin folder there is no sites folder. Link to comment https://forums.phpfreaks.com/topic/67077-solved-includes-not-sharing-variables/#findComment-336508 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.