Jump to content

init.php


unemployment

Recommended Posts

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?

 

Link to comment
https://forums.phpfreaks.com/topic/244253-initphp/
Share on other sites

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?

Link to comment
https://forums.phpfreaks.com/topic/244253-initphp/#findComment-1255248
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.