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