Jump to content

[SOLVED] auto_prepend_file variables go out of scope in the target php file


dactex

Recommended Posts

Hello PHP masters,

 

I use a site root folder on my server which contains the root folders for multiple websites. I then use a server-wide auto_prepend file to set the site root folder and then include the appropriate site settings file to set up the proper include_path for the specific targeted website, depending on the request.

The following pseudocode shows what I have going on:

The server_prepend_file contains

 

<?php

// Doc_root of site1 is E:/sites/site1

$server_root_dir = 'E:/sites' ;

$site_folder = "site1" ;

$settings_filename = "site_settings.php" ;

...

// Depending on the request:

 

$site_root_dir = $server_root_dir . "/" . $site_folder ;

$site_settings = $site_root_dir . "/" . $settings_filename;

ini_set('include_path' , ini_get('include_path') .

include ($site_settings);

// inside this included file, $server_root_dir and $site_root_dir

//appear to still be in scope as expected, but go away once entering the target.

?>

 

I request http://site1.com/index.php

 

The include_path setup works, since my headers, footers, and site-specific functions are getting included fine, but any variables I may have set inside the site_settings.php -and- the auto_prepend_file go out of scope when index.php begins.

 

I have to put :

global $setting_var;

 

for every variable I need inside every target file in my site, which seems to be defeating the purpose of the auto_prepend_file and my site_settings.php file.

 

I can do:

$setting_var = "Hello!!!";

global $setting_var;

 

inside the site_settings.php file, but it still goes out of scope in the target.

 

Is this by design?

 

I am starting to think there is a nuance about "include"-ing within the "auto_prepend_file" that I am unaware of, and that I'll have to think of a better solution with the site_settings.php file, but that still doesn't explain the auto_prepend_file vars going out of scope.

 

Any ideas?

Link to comment
Share on other sites

error in posted code... noted in green below...

Hello PHP masters,

 

I use a site root folder on my server which contains the root folders for multiple websites. I then use a server-wide auto_prepend file to set the site root folder and then include the appropriate site settings file to set up the proper include_path for the specific targeted website, depending on the request.

The following pseudocode shows what I have going on:

The server_prepend_file contains

 

<?php

// Doc_root of site1 is E:/sites/site1

$server_root_dir = 'E:/sites' ;

$site_folder = "site1" ;

$settings_filename = "site_settings.php" ;

...

// Depending on the request:

 

$site_root_dir = $server_root_dir . "/" . $site_folder ;

$site_settings = $site_root_dir . "/" . $settings_filename;

ini_set('include_path' , ini_get('include_path') . ";" . $site_root_dir);

include ($site_settings);

// inside this included file, $server_root_dir and $site_root_dir

//appear to still be in scope as expected, but go away once entering the target.

?>

 

I request http://site1.com/index.php

 

The include_path setup works, since my headers, footers, and site-specific functions are getting included fine, but any variables I may have set inside the site_settings.php -and- the auto_prepend_file go out of scope when index.php begins.

 

I have to put :

global $setting_var;

 

for every variable I need inside every target file in my site, which seems to be defeating the purpose of the auto_prepend_file and my site_settings.php file.

 

I can do:

$setting_var = "Hello!!!";

global $setting_var;

 

inside the site_settings.php file, but it still goes out of scope in the target.

 

Is this by design?

 

I am starting to think there is a nuance about "include"-ing within the "auto_prepend_file" that I am unaware of, and that I'll have to think of a better solution with the site_settings.php file, but that still doesn't explain the auto_prepend_file vars going out of scope.

 

Any ideas?

Link to comment
Share on other sites

As Emily Litella often said: "Never mind." ::)

 

My debugger was making me ill.

 

It would not display the values of global variables unless I try to reference them within the target script. they're there if I try to use them...

 

DOH! (Homer (not of ancient epic fame))

 

 

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.