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>
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.