JavaScript-How does the server initiate HTTP Basic authentication??

Source: Internet
Author: User
In js ajaxThe following is the case:

var xhr = new XMLHttpRequest();    // 下面的第四个,第五个参数怎么使用??    xhr.open('get' , 'authorization.php' , true , username , password);    xhr.send();

So far have not used ajax open the method of the fourth, the fifth parameter, write Ajax operation class today when the fourth, fifth parameters is always a lump, want to thoroughly understand him.

The web says it needs to be available on the http 基本认证的 page 第四个,第五个参数 .

But I just don't understand php页面怎么弹出认证框 ?

I have tried:

 header('Authorization: username:password');

But this is supposed to be the case, ajax 请求中头设置 anyway, php 这一块怎么弄?? no clue.

Can you post this to 认证的 js 代码, php 代码 study (temporarily not involved oAuth 认证 , first learn the most original ha, and then on oAuth )?

Reply content:

In the js ajax following scenario:

var xhr = new XMLHttpRequest();    // 下面的第四个,第五个参数怎么使用??    xhr.open('get' , 'authorization.php' , true , username , password);    xhr.send();

So far have not used ajax open the method of the fourth, the fifth parameter, write Ajax operation class today when the fourth, fifth parameters is always a lump, want to thoroughly understand him.

The web says it needs to be available on the http 基本认证的 page 第四个,第五个参数 .

But I just don't understand php页面怎么弹出认证框 ?

I have tried:

 header('Authorization: username:password');

But this is supposed to be the case, ajax 请求中头设置 anyway, php 这一块怎么弄?? no clue.

Can you post this to 认证的 js 代码, php 代码 study (temporarily not involved oAuth 认证 , first learn the most original ha, and then on oAuth )?

Just now, want to be PHP to collect others, basic certification, the official example:

HTTP Authentication with PHP


  
   Hello {$_SERVER['PHP_AUTH_USER']}.

"; echo "

You entered {$_SERVER['PHP_AUTH_PW']} as your password.

"; }?>

The normal network request status is 200, you want the browser to pop up the Basic authentication window, return to status 401 can

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.