案例----登陆

静态页面

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>Document</title>
</head>
<body>
  <div>
    <form action="page5-post.php" method="POST">
      用户名:<input type="text" name="username">
      密码:<input type="password" name="password">
      <input type="submit" value="登陆">
    </form>
  </div>
</body>
</html>

PHP

<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>Document</title>
</head>

<body>
  <div>
    <?php
    // 这里根据表单中的name属性获取值
    $uname = $_POST['username'];
    $pw = $_POST['password'];
    // 设置服务器响应的文件类型
    header("Content-Type:text/html; charset:utf-8");
    if ($uname == 'zs' && $pw == '123') {
      echo '登陆成功';
    } else {
      echo '请输入正确的账号密码';
    }
    ?>
  </div>
</body>

</html>
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容