 restws_basic_auth/restws_basic_auth.module | 14 +++++++++++++-
 1 file changed, 13 insertions(+), 1 deletion(-)

diff --git a/restws_basic_auth/restws_basic_auth.module b/restws_basic_auth/restws_basic_auth.module
index 3b611d1..f0c68e6 100644
--- a/restws_basic_auth/restws_basic_auth.module
+++ b/restws_basic_auth/restws_basic_auth.module
@@ -11,14 +11,26 @@
  * Performs a user login from the credentials in the HTTP Authorization header.
  */
 function restws_basic_auth_init() {
+
+  // Try to get the headers via PHP
+  if ($headers = getallheaders()) {
+    if (isset($headers['Authorization']) && !empty($headers['Authorization'])) {
+      $authentication = base64_decode(substr($headers['Authorization'], 6));
+    }
+  }
+  
   // Try to fill PHP_AUTH_USER & PHP_AUTH_PW with REDIRECT_HTTP_AUTHORIZATION
   // for compatibility with Apache PHP CGI/FastCGI.
   // This requires the following line in your ".htaccess"-File:
   // RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
-  if (!empty($_SERVER['REDIRECT_HTTP_AUTHORIZATION']) && !isset($_SERVER['PHP_AUTH_USER']) && !isset($_SERVER['PHP_AUTH_PW'])) {
+  elseif (!empty($_SERVER['REDIRECT_HTTP_AUTHORIZATION']) && !isset($_SERVER['PHP_AUTH_USER']) && !isset($_SERVER['PHP_AUTH_PW'])) {
     $authentication = base64_decode(substr($_SERVER['REDIRECT_HTTP_AUTHORIZATION'], 6));
+  }
+  
+  if (isset($authentication)) {
     list($_SERVER['PHP_AUTH_USER'], $_SERVER['PHP_AUTH_PW']) = explode(':', $authentication);
   }
+  
   if (user_is_anonymous() && isset($_SERVER['PHP_AUTH_USER']) && isset($_SERVER['PHP_AUTH_PW'])) {
     // Login only user names that match a pattern.
     $user_regex = variable_get('restws_basic_auth_user_regex', '/^restws.*/');