function _securesite_mechanism in Secure Site 6.2
Same name and namespace in other branches
- 7.2 securesite.module \_securesite_mechanism()
Return the authentication method used by the client, or FALSE if the client did not send credentials.
2 calls to _securesite_mechanism()
- securesite_boot in ./
securesite.module - Implementation of hook_boot().
- _securesite_digest_auth in ./
securesite.inc - Perform digest authentication.
File
- ./
securesite.module, line 123 - Enables HTTP authentication or an HTML form to restrict site access.
Code
function _securesite_mechanism() {
static $mechanism;
if (!isset($mechanism)) {
// PHP in CGI mode work-arounds. Sometimes "REDIRECT_" prefixes $_SERVER
// variables. See http://www.php.net/reserved.variables.
if (empty($_SERVER['HTTP_AUTHORIZATION']) && !empty($_SERVER['REDIRECT_HTTP_AUTHORIZATION'])) {
$_SERVER['HTTP_AUTHORIZATION'] = $_SERVER['REDIRECT_HTTP_AUTHORIZATION'];
}
if (!empty($_SERVER['HTTP_AUTHORIZATION'])) {
require_once './includes/unicode.inc';
list($type, $authorization) = explode(' ', $_SERVER['HTTP_AUTHORIZATION'], 2);
switch (drupal_strtolower($type)) {
case 'digest':
$_SERVER['PHP_AUTH_DIGEST'] = $authorization;
break;
case 'basic':
list($_SERVER['PHP_AUTH_USER'], $_SERVER['PHP_AUTH_PW']) = explode(':', base64_decode($authorization), 2);
break;
}
}
$mechanism = FALSE;
$types = variable_get('securesite_type', array(
SECURESITE_BASIC,
));
rsort($types, SORT_NUMERIC);
foreach ($types as $type) {
switch ($type) {
case SECURESITE_DIGEST:
if (isset($_SERVER['PHP_AUTH_DIGEST'])) {
$mechanism = SECURESITE_DIGEST;
break 2;
}
break;
case SECURESITE_BASIC:
if (isset($_SERVER['PHP_AUTH_USER']) || isset($_SERVER['PHP_AUTH_PW'])) {
$mechanism = SECURESITE_BASIC;
break 2;
}
break;
case SECURESITE_FORM:
if (isset($_POST['form_id']) && $_POST['form_id'] == 'securesite_user_login') {
$mechanism = SECURESITE_FORM;
break 2;
}
break;
}
}
}
return $mechanism;
}