variable scope in subdirectory

Hello :slight_smile:

I’ve encountered an issue today and I’m not quite sure what the problem is, so I hope one of you can help me out here.

I’ve created a subdomain and within the following folder structure:

  • city
    • includes

      settings.php

    index.php

  • global
    • php

    header.php

In my settings.php file I’ve defined a couple of variables I’d like to use throughout my script.
I’d like to include the settings file into my index.php and right after include my header.php in which
I try to access the varaibles I’ve previously defined in my settings.php

e.g

– settings.php —
define(“CITY”, “My current city”);

– header.php –
echo CITY;

– index.php –
require_once(“includes/settings.php”);
require_once("…/global/php/header.php");

What happens is that my defined variables are accessible in my settings.php aswell as in my index.php however they’re undefined in my header file.

If anyone has the solution to my problem other than duplicating and moving my header files into the respective city folders that’d be great :slight_smile:

Hi,

replace this code
[php]
require_once(“includes/settings.php”);
require_once("…/global/php/header.php");
[/php]
with this code.
[php]
$root_path = $_SERVER[‘DOCUMENT_ROOT’];
require_once($root_path."/includes/settings.php");
require_once($root_path."/global/php/header.php");
[/php]

Sponsor our Newsletter | Privacy Policy | Terms of Service