dactex Posted September 6, 2009 Share Posted September 6, 2009 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? Quote Link to comment Share on other sites More sharing options...
dactex Posted September 6, 2009 Author Share Posted September 6, 2009 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? Quote Link to comment Share on other sites More sharing options...
dactex Posted September 6, 2009 Author Share Posted September 6, 2009 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)) Quote Link to comment Share on other sites More sharing options...
PFMaBiSmAd Posted September 6, 2009 Share Posted September 6, 2009 The global keyword has absolutely no meaning outside of a function definition. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.