首頁 >後端開發 >php教程 >PHP首部認證

PHP首部認證

WBOY
WBOY原創
2016-07-29 09:02:511148瀏覽

PHP首部認證

<code><span><span><?php</span><span>// User name and password for authentication</span><span>$username</span> = <span>'rock'</span>;
  <span>$password</span> = <span>'roll'</span>;

  <span>if</span> (!<span>isset</span>(<span>$_SERVER</span>[<span>'PHP_AUTH_USER'</span>]) || !<span>isset</span>(<span>$_SERVER</span>[<span>'PHP_AUTH_PW'</span>]) ||
    (<span>$_SERVER</span>[<span>'PHP_AUTH_USER'</span>] != <span>$username</span>) || (<span>$_SERVER</span>[<span>'PHP_AUTH_PW'</span>] != <span>$password</span>)) {
    <span>// The user name/password are incorrect so send the authentication headers</span>
    header(<span>'HTTP/1.1 401 Unauthorized'</span>);
    header(<span>'WWW-Authenticate: Basic realm="Guitar Wars"'</span>);
    <span>exit</span>(<span>'<h2>Guitar Wars</h2>Sorry, you must enter a valid user name and password to access this page.'</span>);
  }
<span>?></span></span></code>
').addClass('pre-numbering').hide(); $(this).addClass('has-numbering').parent().append($numbering); for (i = 1; i ').text(i)); }; $numbering.fadeIn(1700); }); });

以上就介紹了PHP首部認證,包含了方面的內容,希望對PHP教學有興趣的朋友有幫助。

陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn