How do I use variables from an included file, and use it for other included files as well?
index
<?php
$tmp = new template($connect);
$tmp->globals('index');
$logged_in = false; //works in all included files
?>
<html>
<head>
<?php $tmp->template('head'); ?> //class method to include file
</head>
<body>
<?php echo $description; ?> //does not work either
include_head.php
<title><?php echo $title; ?></title>//does not echo anything
index_globals.php
<?php
$title="title";
$description="description";
?>
How I am including
public function template($file){
if(isset($file) && file_exists($this->dir.$file.".php")){
ob_start();
include($this->dir.$file.".php");
$template = ob_get_contents();
return $template;
}
}
Globals Function
public function globals($name){
if(isset($name) && file_exists($this->dir.$name."_globals.php")){
include($this->dir.$name."_globals.php");
}
}