案例----登陆
2020-01-09 本文已影响0人
王远清orz
静态页面
<!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>