1 system_test.module system_test_basic_auth_page()

Check HTTP headers for authentication.

Return value

string: The username and password passed in through web authentication.

File

core/modules/simpletest/tests/system_test.module, line 190
Test module for system functions.

Code

function system_test_basic_auth_page() {
  // The Authorization HTTP header is forwarded via Backdrop's .htaccess file even
  // for PHP CGI SAPIs.
  if (isset($_SERVER['HTTP_AUTHORIZATION'])) {
    $authorization_header = $_SERVER['HTTP_AUTHORIZATION'];
  }
  // If using CGI on Apache with mod_rewrite, the forwarded HTTP header appears
  // in the redirected HTTP headers. See
  // https://github.com/symfony/symfony/blob/HEAD/src/Symfony/Component/HttpFoundation/ServerBag.php#L61
  elseif (isset($_SERVER['REDIRECT_HTTP_AUTHORIZATION'])) {
    $authorization_header = $_SERVER['REDIRECT_HTTP_AUTHORIZATION'];
  }
  // Resemble PHP_AUTH_USER and PHP_AUTH_PW for a Basic authentication from
  // the HTTP_AUTHORIZATION header. See
  // http://www.php.net/manual/features.http-auth.php
  list($user, $pw) = explode(':', base64_decode(substr($authorization_header, 6)));
  $output = format_string('Username is @username.', array('@username' => $_SERVER['PHP_AUTH_USER']));
  $output .= format_string('Password is @password.', array('@password' => $_SERVER['PHP_AUTH_PW']));
  return $output;
}