unemployment Posted August 8, 2011 Share Posted August 8, 2011 I want to make an init.php file that includes my lib files and that will set my global page variable. In the include file I have... ob_start(); session_start(); date_default_timezone_set("America/New_York"); setlocale(LC_MONETARY, 'en_US.UTF-8'); $page = substr(end(explode(DIRECTORY_SEPARATOR, $_SERVER['PHP_SELF'])), 0, -4); $path = dirname(__FILE__); foreach (glob($path . '/lib/*.inc.php') as $lib_file) { include($lib_file); } And in my header.php file I have... $titleArray = array( 'index' => 'Home', ); $title = $titleArray[$page]; if (array_key_exists($page, $titleArray) !== false) { $title .= " | Jason's site"; } But I get undefined index errors. Notice: Undefined variable: page in C:\xampp\htdocs\assets\header.php on line 7 Notice: Undefined index: in C:\xampp\htdocs\assets\header.php on line 7 Notice: Undefined variable: page in C:\xampp\htdocs\assets\header.php on line 9 How can I make sure my init.php is being launch and that my page variable is being set? Quote Link to comment https://forums.phpfreaks.com/topic/244253-initphp/ Share on other sites More sharing options...
cunoodle2 Posted August 8, 2011 Share Posted August 8, 2011 which page are you accessing via the URL? header.php? If so I don't see the init.php being included in it. Quote Link to comment https://forums.phpfreaks.com/topic/244253-initphp/#findComment-1254515 Share on other sites More sharing options...
trq Posted August 8, 2011 Share Posted August 8, 2011 You really should look into auto loading too instead of arbitrarily loading every library you have whether you need it or not. Quote Link to comment https://forums.phpfreaks.com/topic/244253-initphp/#findComment-1254585 Share on other sites More sharing options...
unemployment Posted August 10, 2011 Author Share Posted August 10, 2011 You really should look into auto loading too instead of arbitrarily loading every library you have whether you need it or not. Hmm yeah... I wasn't including the init.php file. It was a bit of a dumb mistake. I thought it was already included in my index.php and that's why my header variables failed. Hmm... I wonder what auto-loading is? Have any good links to tutorials for it? Quote Link to comment https://forums.phpfreaks.com/topic/244253-initphp/#findComment-1255248 Share on other sites More sharing options...
trq Posted August 10, 2011 Share Posted August 10, 2011 autoload or spl_autoload. I assume your lib files contain classes? Quote Link to comment https://forums.phpfreaks.com/topic/244253-initphp/#findComment-1255258 Share on other sites More sharing options...
unemployment Posted August 10, 2011 Author Share Posted August 10, 2011 autoload or spl_autoload. I assume your lib files contain classes? Actually, no... most of them don't. I've only been programming php for 8 or 9 months and I haven't quite gotten the hang of OOP. Quote Link to comment https://forums.phpfreaks.com/topic/244253-initphp/#findComment-1255259 Share on other sites More sharing options...
trq Posted August 10, 2011 Share Posted August 10, 2011 Ah well. Don't bother. Quote Link to comment https://forums.phpfreaks.com/topic/244253-initphp/#findComment-1255260 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.