Jump to content

[SOLVED] Includes not sharing variables


Xeoncross

Recommended Posts

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
Share on other sites

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
Share on other sites

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.