php用户名和密码的简单验证

浏览:1128 发布日期:2019/12/12 分类:功能实现 关键字: -
-
5.php页面提交form表单
<html>
 <head></head>
 <body>
 <form action = "5_1.php" method = "post">
 username:<input type = "text" name = "username"></br>
 password:<input type = "text" name = "password"></br>
 <input type = "submit" value = "提交">  
 <input type = "reset" value = "重置">
 </form>
 </body>
</html>

 

5_1.php页面接收form表单,并进行处理
//设置用户名和密码

   $arr_user = array("user","pwd");
   $arr_pwd = array("user"=>"1111","pwd"=>"2222");

//接收从表单提交过来的值,并进行判断:
   $username = isset($_POST['username'])?$_POST['username']:"";
   $pwd = isset($_POST['password'])?$_POST['password']:"";

//用户名和密码的验证:
  if(in_array($username,$arr_user)){
         if($pwd == $arr_pwd[$username]){
               echo "登陆成功";
         }else{
             die("密码错误");   //die是停止程序运行
         }
   }else {
       die("用户名错误");
}

//注意若是把表单提交和表单接收处理放在一个php页面里,那么请把die输出命令换成echo输出命令,因为die会直接显示验证结果,不会进入用户名和密码输入画面。
评论( 相关
后面还有条评论,点击查看>>