View Full Version : Template parser page not woking with login system function calls

11-13-2010, 08:29 PM
Hi all,
Thanks for taking the time to read my post.

I've recently built a php/MySQL CMS and used a simple template parser to create new pages, all based around the same HTML file with placeholders to replace with text/pages to be sucked into these placeholders (<!--main-->).

Template class:

class Page
var $page;

function Page($template = "assets/templates/template.htm") {
if (file_exists($template))
$this->page = join("", file($template));
die("Template file $template not found.");

function parse($file) {
$buffer = ob_get_contents();
return $buffer;

function replace_tags($tags = array()) {
if (sizeof($tags) > 0)
foreach ($tags as $tag => $data) {
$data = (file_exists($data)) ? $this->parse($data) : $data;
$this->page = eregi_replace("<!--" . $tag . "-->", $data,
die("No tags designated for replacement.");

function output() {
echo $this->page;

Which works perfectly using:

"title" => "Categories",
"navigation" => "main/navigation.php",
"main" => "main/category.php"

for each page. The functionality is in the "main" placeholder.

I'm trying to integrate the JpMaster77's login system (http://www.evolt.org/node/60384) into this, so i can show logged in and admin only content on the "main" pages.

However, if i try to use the "if person is logged in/has session, or isAdmin(), it doesn't work when parsed, it just trips over any if(session) etc and goes to the else. When the page being drawn in is viewed by itself, this works.

echo "hello there Admin!";
The login system itself is from 2004, so i'm not sure whether it's the way the isAdmin() function is called by old PHP syntax, or if the parser is not allowing this to run properly....

Does anyone have any ideas what could be affecting this working properly please?

Thank you.


11-14-2010, 12:26 PM
Have you started the session somewhere with session_start()? Also, this is outdated and unnecessary:

$this->page = eregi_replace("<!--" . $tag . "-->", $data, $this->page);

The eregi_ functions are deprecated and you're working with a known string, so use str_.

$this->page = str_replace('<!--'.$tag.'-->', $data, $this->page);