title: Authorizing Basic authentication fails for rest calls using javascript in php
body: <p>API calls from javascript fails and from PHP curl they are fine.</p>
  
  <p>PHP Script to check authentication</p>
  
  <hr>
  
  <pre><code> if (!isset($_SERVER['PHP_AUTH_USER'])) {
          header('WWW-Authenticate: Basic realm="Test auth"');
          header('HTTP/1.0 401 Unauthorized');
          echo '{"status":"401","message":"Unauthorized"}';
          exit;
      } else {
          $user= $_SERVER['PHP_AUTH_USER'];
          $pass =  $_SERVER['PHP_AUTH_PW'];
      }
  </code></pre>
  
  <h2>Javascript // fails</h2>
  
  <pre><code>var xhr = new XMLHttpRequest();
  var apiid = 'admin';
  var apipassword = '123';
  var requesturl = 'http://localhost/man/api/man/GetLanguages';
  xhr.open('POST', requesturl, false, apiid, apipassword);
  xhr.send('{}');
  if(xhr.status == 200){
       alert(xhr.responseText);
  } 
  </code></pre>
  
  <h2>PHP curl call</h2>
  
  <pre><code>$ch = curl_init($url);                                                                
  curl_setopt($ch, CURLOPT_CUSTOMREQUEST, POST");                                                                     
  curl_setopt($ch, CURLOPT_POSTFIELDS, $data);                                                                  
  curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);                                                                      
  curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Length: ' . strlen($data),'Authorization: Basic YWRtaW46MTIz'));     
  echo $result = curl_exec($ch);
  </code></pre>