[SOLUTION] Password Protected Pages

For questions and problems with the CMS core. This board is NOT for any 3rd party modules, addons, PHP scripts or anything NOT distributed with the CMS made simple package itself.
Post Reply
Krapulator
New Member
New Member
Posts: 4
Joined: Sat Aug 11, 2007 4:44 am

[SOLUTION] Password Protected Pages

Post by Krapulator »

I came up with a variation on this that doesn't require editing the core files.

I created a user-defined tag called password_protect and added the following code:

Code: Select all

function call_http_authentication() {
   header('WWW-Authenticate: Basic realm="Enter username and password"');
   header('HTTP/1.0 401 Unauthorized');
   echo 'Authorisation Failed. Refresh page to try again.';
   exit;
}

function call_to_authenticate($params) {
if(isset($_SERVER['PHP_AUTH_USER']) && $_SERVER['PHP_AUTH_USER'] == $params['username'] && isset($_SERVER['PHP_AUTH_PW']) && $_SERVER['PHP_AUTH_PW'] == $params['password']) {} 
   else
      call_http_authentication();
}

 call_to_authenticate($params);
I then created a template for the password protected pages and added the tag like this (right at the top before the {process_pagedata directive}):

Code: Select all

{password_protect username="hello" password="you"}
Post Reply

Return to “CMSMS Core”