2

I have a site which is using Basic Authentication, visitor can login with predefined credentials. I can reach the $_SERVER["PHP_AUTH_USER"] variable, so everything works fine here. But when I'm trying to post data with jQuery AJAX in the same domain, I can't reach the $_SERVER["PHP_AUTH_USER"] variable (not set in the $_SERVER).

Environment:
Server version: Apache/2.4.7 (Ubuntu)
PHP Version: 5.5.9-1
Ubuntu: 4.9
(Server API: Apache 2.0 Handler, so not CGI)
Chromium: 41.0.2272.76
Ubuntu 14.04 (64-bit)

Can anyone help with this problem?

Jouke van der Maas
  • 4,117
  • 2
  • 28
  • 35
RobbeR
  • 485
  • 6
  • 23

1 Answers1

0

Along with greet, commented that the server will accept your application if you send in the request authentication, therefore you within Jquery Ajax method, and define Dentrol method the Autentification property through getAllResponseHeaders () function, an important point is in basic mode of authentication uses javascript base 64 (btoa) to encrypt the username and pass, I hope you find it useful and invite you to visit my github, enter link description here, have some useful ools Built to to validate data when luck

$.ajax({
        url  : 'test_2.php',
        type : 'GET',
        beforeSend: function (xhr) {
            xhr.setRequestHeader('Authorization', 'Basic ZWxlbWVudG86ZWxlbWVudG8=');
        },
        data: {},
        success: function (e) {
            console.log(e)
        },
        error: function (e) {
            console.log(e)
        },
    });