灰儿 发表于 2021-11-13 22:57:10

PHP实现简单登录验证(未连接数据库)

题目:
创建一个登陆表单,包括登录名、密码文本框和提交按钮,创建完后使用PHP获得用户输入的登录名和密码。登录名为 “user”,密码为 “123456” 时提示登陆成功。


<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport"
          content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>登录验证表单</title>
</head>
<body>
    <form name="form1" method="post">
      <div>
            登录名:<input type="text" name="username"><br/>
            密码:<input type="password" name="password"><br/>
            <input type="submit" name="submit" value="提交">
      </div>
    </form>
</body>
</html>
<?php
    if(isset($_POST["submit"])){
      $user=$_POST["username"];
      $psw=$_POST["password"];
      if($user=="user" && $psw=="123456"){
            echo "<script>alert('登陆成功!')</script>";
      }else{
            echo "<script>alert('用户名或密码不正确,请重新输入!')</script>";
      }
    }
?>

页: [1]
查看完整版本: PHP实现简单登录验证(未连接数据库)