LIMITING DIRECTORY ACCESS AND PROTECTING DIRECTORIES - Jun 1st, 2011


Thanks to Dave Edis from Interactive Tools for this part.

Since all the files are PHP they are executed server side and protected from prying eyes by default.

1) In your user accounts editor, create a multi value list field called allowedFolders
The values I used are:
board_access
committee_access
general_access

Go into the User Accounts list and check some values in your account to authorize access to some of those folders.

2) In the root directory of your site create 3 folders:
board_access
committee_access
general_access

3) In each folder upload a test file called access.php

the code in each of the access.php files is:



<?php
require_once "../cmsAdmin/lib/viewer_functions.php";
if (!@
$GLOBALS['WEBSITE_MEMBERSHIP_PLUGIN']) { die("You must activate the Website Membership plugin before you can
access this page."); }
if (!
$CURRENT_USER) { websiteLogin_redirectToLogin(); }

//
$folderName = basename(dirname(__FILE__));
$allowAccess = preg_match("/\t$folderName\t/", $CURRENT_USER['allowedFolders']);
if (!
$allowAccess) { die("You don't have access to this folder!"); }
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Access Test</title>
</head>

<body>
<?php echo $CURRENT_USER['allowedFolders'] ?>
</body>
</html>



The code in the body just prints out the directories that the particular member is authorized to view.

After you’ve got the basic code working, you can paste the code required into an existing page, upload it to one of
those directories, and make sure it all works as planned.



The materials on this web site have been created for use with CMS Builder content management software. CMS Builder software is published and licensed for use by InteractiveTools.com. Please contact Interactive Tools for information on the downloading of the software or the purchasing of licenses.


Terms of Service