You are here:  » Using Admin login throughout the site.


Using Admin login throughout the site.

Submitted by stevewales20 on Tue, 2013-08-13 15:06 in

Hi David,

How easy would it be for me to adopt the admin sessions throughout the site, i'd like to be able to browse the site and see certain things that others shouldn't. So I login in the admin area, and then i can browse the whole site, and depending on what i want to show i can use a trigger.

I can see this:

$admin_checkPassword = TRUE;

I was wondering where that check is made and if i can apply it to certain places. So if logged in show this snippet..

Thanks
Steve

Submitted by support on Tue, 2013-08-13 19:12

Hi Steve,

What you'd need to do is set the admin login cookie to have a path of "/" (top level) rather than being limited to the current diretory. In admin/login.php, look for the following code at line 21:

  setcookie("admin",md5($remoteAddr.$config_adminPassword));

...and REPLACE with;

  setcookie("admin",md5($remoteAddr.$config_adminPassword),0,"/");

Next, you'll need to add a utility function to validate the cookie against the admin password (can't just use isset($_COOKIE["admin"]) unfortunately otherwise anyone could just set a cookie called "admin"!!) so to do this, add the following new function to includes/tapestry.php:

function tapestry_isAdmin()
{
  global $config_adminPassword;
  return (
     (isset($_COOKIE["admin"]))
     &&
     ($_COOKIE["admin"] == md5($_SERVER["REMOTE_ADDR"].$config_adminPassword))
     );
}

With that in place, you will be able to add code / HTML etc. conditional upon the return value (TRUE or FALSE) of a call to tapestry_isAdmin() for example, within an HTML section:

<?php if (tapestry_isAdmin()): ?>
You are an administrator!
<?php endif; ?>

Or within a PHP section:

if (tapestry_isAdmin())
{
  print "You are an administrator!";
}

Cheers,
David.
--
PriceTapestry.com

Submitted by stevewales20 on Wed, 2013-08-14 08:52

Great Stuff,

Thanks very much. I'll test it in a bit. Will help process things alot faster :)

Cheers,
Steve