Page 1 of 1

[SOLUTION] Password Protected Pages

Posted: Tue Jun 19, 2012 9:02 pm
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"}