theepan Posted March 29, 2008 Share Posted March 29, 2008 Hello There, I am trying to include one php file that includes another php file. All three files are in different folders. The variables in first php page is not visible. Folder Structure: -Webapp -config/config.php -incs/header.php <- includes config -public_html/index.php <- includes config. Variables in config.php from header.php is not visible in index.php. If I run header.php, config.php variables are visible. Code: index.php ------------------------------ <?php require_once("../../incs/header.php"); head('Home'); foot(); ?> header.php ----------------------------- <?php //include_once("../config/config.php"); function head($title = " "){ ?> <html> <head> <title><? echo "$title - $glo_title"?></title> </head> <body> <?php } function foot(){ ?> </body></html> <?php } ?> config.php ------------------------------- <?php /** TITLE */ global $glo_title; $glo_title = "123auto"; /** USERNAME/PASSWORDS */ //MySQL global $username; global $password; $username = "testuser"; $password = "test"; ?> ----- thanks in advance EDITED BY WILDTEEN88: Please use code tags ( ) when posting code Link to comment https://forums.phpfreaks.com/topic/98530-help-please-recursive-include-variables-not-visible/ Share on other sites More sharing options...
cunoodle2 Posted March 29, 2008 Share Posted March 29, 2008 In each include file try using the full directory path like /home/theepan/public_html/yourstuff or whatever your home directory is according to your server. Link to comment https://forums.phpfreaks.com/topic/98530-help-please-recursive-include-variables-not-visible/#findComment-504268 Share on other sites More sharing options...
PFMaBiSmAd Posted March 29, 2008 Share Posted March 29, 2008 Nested includes/requires are relative to the first/main file (unless you change the working directory.) You are also using a mix of require and include, so the include could be failing and you won't know it unless you enable all php errors and check your web server log file for errors. To avoid all problems with include/require paths, do what cunoodle2 has suggested and always use a full/absolute file system path. If you use $_SERVER['DOCUMENT_ROOT'] to form the path, you won't need to know what it actually is and you won't need to change your code if you ever move servers where the file system path is different. Link to comment https://forums.phpfreaks.com/topic/98530-help-please-recursive-include-variables-not-visible/#findComment-504285 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.