Home  >  Article  >  php教程  >  php用户登录代码

php用户登录代码

WBOY
WBOYOriginal
2016-05-25 16:40:411823browse

本款提供二种用户登录的方法,一种是普通的php mysql用户登录,另一种是利用window验证来登录,后来一种更安全,但不适合于其它应用.

方法一,window 验证用户登录,代码如下:

<?php
$admin_name="admin"; 
$admin_pawd="admin"; 
if($php_auth_user!=$admin_name||$php_auth_pw!=$admin_pawd)//开源代码phpfensi.com 
{ 
   header(&#39;www-authenticate: basic realm="系统验证"&#39;); 
   header(&#39;http/1.0 401 unauthorized&#39;); 
   echo "服务器拒绝请求,你没有权限!";  
   exit();  
} 
 
if (empty($_server[&#39;php_auth_user&#39;])) { 
   header("content-type: text/html; charset=big5"); 
   header(&#39;www-authenticate: basic realm=" authentication "&#39;); 
   header(&#39;http/1.0 401 unauthorized&#39;); 
   echo &#39;请输入正确的账号及密码, 不可以取消!&#39;; 
   exit; 
} else { 
   echo "你登录的账号是 ".$_server[&#39;php_auth_user&#39;]."<br>"; 
   echo "你使用的密码是 ".$_server[&#39;php_auth_pw&#39;]."<p>"; 
   $correctname="john"; 
   $correctpwd="1234" ; 
   if (($_server[&#39;php_auth_user&#39;] != $correctname) or ($_server[&#39;php_auth_pw&#39;] !=$correctpwd)){ 
       echo "登录失败, 请打开新的浏览器重新登录"; 
    }else{ 
    echo "登录成功....."; 
   } 
}
?>

方法二 php mysq,代码如下:

<?php 
   if (($_post[&#39;name&#39;] != "john") or ($_post[&#39;passwd&#39;] != "1234")): 
?> 
<html> 
<title>登录画面</title> 
<body> 
<b>未输入账号或密码, 或账号,密码不正确 </b><p> 
<form action=<?php echo $_server[&#39;php_self&#39;] ?> method=post> 
账号 <input type=text name=name value="请输入账号" size=10><p> 
密码 <input type=password name=passwd size=10><p> 
<input type=submit value=" 登录 "> 
<input type=reset  value=" 清除 "> 
</form> 
</body> 
</html> 
<?php 
    else: 
    echo "登录成功 .....<p>"; 
    echo "你登录的账号是 ".$_post[&#39;name&#39;]."<br>"; 
    echo "你使用的密码是 ".$_post[&#39;passwd&#39;]; 
    endif 
?>


永久链接:

转载随意!带上文章地址吧。

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