Am working on some website, where i have php files in includes folder and navbar, header and footer in layouts folder. When i require functions in includes folder in my index.php they work properly but when i call the same functions in header or navbar the blow with error Undefined index and the name of the function. What can i do?
Index.php:
<?php
require("../includes/initialize.php");
require_once(LIB_PATH.DS.'session.php');
?>
<!-- header -->
<?php
include_layout_template('header.php');
include_layout_template('navbar.php');
?>
<?php echo output_message($message); ?>
navbar.php:
<div class="agileits_header">
<div class="container">
<div class="w3l_offers">
</div>
<div class="agile-login">
<ul>
<?php if(!$session->is_logged_in()): ?>
<li><a href="register.php"> Create Account </a></li>
<li><a href="login.php">Login</a></li>
<?php else: ?>
<li><a href="profile.php">Profile</a></li>
<li><a href="logout.php">Logout</a></li>
<?php endif; ?>
<li><a href="contact.php">Help</a></li>
</ul>
</div>
This is my initialize.php file:
defined('DS') ? null : define('DS', DIRECTORY_SEPARATOR);
defined('SITE_ROOT') ? null :
define('SITE_ROOT', DS.'xampp'.DS.'htdocs'.DS.'supermarket');
defined('LIB_PATH') ? null : define('LIB_PATH', SITE_ROOT.DS.'includes');
// load config file first
require_once(LIB_PATH.DS.'config.php');
// load basic functions next so that everything after can use them
require_once(LIB_PATH.DS.'functions.php');
require_once(LIB_PATH.DS.'validation_functions.php');
// load core objects
require_once(LIB_PATH.DS.'database.php');
require_once(LIB_PATH.DS.'database_object.php');
require_once(LIB_PATH.DS.'pagination.php');
// load database-related classes
require_once(LIB_PATH.DS.'user.php');
require_once(LIB_PATH.DS.'admin.php');
require_once(LIB_PATH.DS.'seed.php');
require_once(LIB_PATH.DS.'comment.php');
?>
Always include all files with absolute path. Don't use '..' for include files.
try this
define('SITE_ROOT', dirname(__FILE__));
OR
define('ROOTPATH', __DIR__);