PHP實作基本認證
<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>
以上就介紹了PHP實作基本認證,包含了方面的內容,希望對PHP教學有興趣的朋友有幫助。