I've inherited a site from a previous (no longer available for help) developer and I'm not much of a PHP coder to begin with so, bear with me.
I keep getting an error that some variables are undefined and the CMS Admin toolbar keeps showing up at the top of the page even though I'm not logged in.
Important Note This only happens in my local development environment.
The error:
Notice: Undefined variable: buttons in /Users/shortname/Sites/sitename.com/public_html/admin/editable.class.php on line 275
Edit Here's the complete file:
Pastebin of editable.class.php
In my page, I've got an include
<?php
include_once 'admin/editable.class.php';
$page = new page(6, 2, 0);
echo $page->get();
?>
It's job is to grab all the page elements from the DB and throw it on the page.
The include appears later in the page as well (in the footer)
<?
include_once "admin/editable.class.php";
$login = new dynamic;
if($login->isAdmin())
{
echo '
<div id="adminBar">
<div>
<h3>Admin Menu</h3> <span class="editable">Editable Pages: <a href="/company/media.php">In The Media</a> | <a href="/company/faq_about.php">FAQ</a> | <a href="/company/tradeshows.php">Tradeshows</a></span> <a class="logout" href="/admin">Logout</a>
</div>
</div>
';
}
?>
Which I assume is what shows the CMS info bar and buttons if you're an authenticated user. The trouble is, I can't authenticate and I can't get the warnings to go away. Here's the authentication functions in editable.class.php:
function isAdmin()
{
if (isset($_COOKIE["admin"]) && $_COOKIE["admin"] === sha1("username".$this->salt.$this->users["username"]))
{
$this->admin = true;
return true;
}
else
{
$this->admin = false;
return false;
}
}
function login()
{
if($this->isAdmin())
{
return true;
}
if (!isset($_SERVER['PHP_AUTH_USER']) || !isset($this->users[$_SERVER['PHP_AUTH_USER']]) || $this->users[$_SERVER['PHP_AUTH_USER']] !== $_SERVER['PHP_AUTH_PW'])
{
header('WWW-Authenticate: Basic realm="Administration"');
header('HTTP/1.0 401 Unauthorized');
echo 'Authorization Required';
exit;
}
else
{
setcookie("admin", sha1("username".$this->salt.$this->users["username"]), 0, "/", ".sitename.com");
$this->admin = true;
return true;
}
}
function logout()
{
header('HTTP/1.0 401 Unauthorized');
setcookie("username", "", time() - 1, "/", ".sitename.com");
}
I tried adding <?php setcookie("username", "", time() - 1, "/", ".sitename.com"); ?> to see if I could clear out the cookie data and remove the admin tools but, that didn't work either. What am I missing on my local development environment that would cause these errors?