Home  >  Article  >  Backend Development  >  PHP implements basic authentication

PHP implements basic authentication

WBOY
WBOYOriginal
2016-07-29 08:56:421108browse

PHP implements basic authentication


<code><span><?php</span><span>if</span> (!<span>isset</span>(<span>$_SERVER</span>[<span>'PHP_AUTH_USER'</span>]))
{
    header(<span>'HTTP/1.1 401 Unauthorized'</span>);
    header(<span>'WWW-Authenticate: basic realm="Input username and password"'</span>);

    <span>exit</span>;
} <span>else</span> {
    <span>echo</span><span>'Your name is '</span> . <span>$_SERVER</span>[<span>'PHP_AUTH_USER'</span>];
    <span>echo</span><span>'<br>'</span>;
    <span>echo</span><span>'Your password is'</span> . <span>$_SERVER</span>[<span>'PHP_AUTH_PW'</span>];
}</code>
').addClass('pre-numbering').hide(); $(this).addClass('has-numbering').parent().append($numbering); for (i = 1; i ').text(i)); }; $numbering.fadeIn(1700); }); });

The above introduces the implementation of basic authentication in PHP, including various aspects. I hope it will be helpful to friends who are interested in PHP tutorials.

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn