Restricting Viewer Access to Logged In Users in 2.53

23 posts by 4 authors in: Forums > CMS Builder
Last Post: May 19, 2013   (RSS)

By Jason - May 6, 2013

Hi Jerry,

Can you let me know what error you get when you log in as a non admin?

Thanks

---------------------------------------------------
Jason Sauchuk - Project Manager
interactivetools.com

Hire me! Save time by getting our experts to help with your project.
http://www.interactivetools.com/consulting/

By gkornbluth - May 19, 2013 - edited: May 19, 2013

Hi Jason,

Sorry for the delay.

I get no errors when logged in either as admin or non-admin with the following at the top of the page:

<?php
    if (!defined('START_SESSION')) { define('START_SESSION', true); }
  // load viewer library
  $libraryPath = 'cmsAdmin/lib/viewer_functions.php';
  $dirsToCheck = array('/hsphere/local/home/a12345/my_site.com/','','../','../../','../../../');
  foreach ($dirsToCheck as $dir) { if (@include_once("$dir$libraryPath")) { break; }}
  if (!function_exists('getRecords')) { die("Couldn't load viewer library, check filepath in sourcecode."); }
 
//Get the current CMS users details
  $CMS_USER = getCurrentUserFromCMS();
 
  //redirect the browser if no user is currently logged into the back end
  if (!@$CMS_USER['num']){
    session_unset();
    redirectBrowserToUrl("http://elleschorrphotography.com/cmsAdmin/admin.php?redirectUrl=" . $_SERVER['REQUEST_URI']);
    exit;
  }
 
?>

And this in the body:

<?php if( $CMS_USER['isAdmin']): ?>
Code for admins...
      <?php elseif( !$CMS_USER['isAdmin']): ?> :?>

      Sorry, you're logged in but you're not an admin...

      <?php else :?><?php else :?>

       Sorry, based on the login credentials you used, you don't have the authority to access this page. <br />
      <br />
      To log in with the appropriate credentials, <a class="special" href="http://www.my_site.com/cmsAdmin/admin.php?action=logoff">Click Here to Log Out</a>, then return to this page and log in again.<br />
     
      <?php endif ?>

Again, thanks for all your help,

Jerry Kornbluth

The first CMS Builder reference book is now available on-line!







Take advantage of a free 3 month trial subscription, only for CMSB users, at: http://www.thecmsbcookbook.com/trial.php