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登录系统的实现过程,包括HTML表单的设计、用户输入的接收及验证逻辑。通过实例展示了如何使用PHP处理表单数据并验证用户名密码。
358

被折叠的 条评论
为什么被折叠?



