Http authorization implements simple web user password verification

WBOY
Release: 2016-07-29 09:07:11
Original
1659 people have browsed it

Recently I want to add a simple username verification mechanism to the web page, because I have used Sina Cloud's http authorization verification method before, and it is naturally perfect for single web page verification.
In fact, the user verification method of http is very simple. Just judge the two values ​​of $_SERVER['PHP_AUTH_USER'] and $_SERVER['PHP_AUTH_PW']. Here is a simple example:

<code><span><span><?php</span><span>if</span> (!<span>isset</span>(<span>$_SERVER</span>[<span>'PHP_AUTH_USER'</span>])) {
    header(<span>'WWW-Authenticate: Basic realm="My Realm"'</span>);
    header(<span>'HTTP/1.0 401 Unauthorized'</span>);
    <span>echo</span><span>'Text to send if user hits Cancel button'</span>;
    <span>exit</span>;
} <span>else</span> {
    <span>echo</span><span>"<p>Hello {$_SERVER['PHP_AUTH_USER']}.</p>"</span>;
    <span>echo</span><span>"<p>You entered {$_SERVER['PHP_AUTH_PW']} as your password.</p>"</span>;
}
<span>?></span></span></code>
Copy after login

in the else of the above code Just check whether the username and password are the same as specified.

').addClass('pre-numbering').hide(); $(this).addClass('has-numbering').parent().append($numbering); for (i = 1; i ').text(i)); }; $numbering.fadeIn(1700); }); });

The above has introduced Http authorization to implement simple web user password verification, including aspects of it. I hope it will be helpful to friends who are interested in PHP tutorials.

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template