admin管理员组文章数量:1122924
登录
re.php(登录的前端界面)
<!DOCTYPE html>
<html><head><meta charset="utf-8"><title>登录页面</title><style>.home{text-align: center;font-weight: bold;}h2 {color: red;font-size: 40px;}.db_name,.db_pass {margin-bottom: 10px;font-size: 20px;}.submit {font-size: 20px;margin-bottom: 10px;}.login{font-size: 20px;margin-left: 300px;}.ch{font-size: 20px;margin-left: 420px;}</style>
</head><body><h2>欢迎来到您的登录界面!</h2><form action="judge.php" method="POST" class="form"><div class="home"><div><span>账 号:<input type="text" required class="db_name" name="db_name" /></span><br><span>密 码:<input type="password" required class="db_pass" name="db_pass" /></span><br></div><div><input type="submit" value="登录" class="submit" /></div><span class="login">还没有账号?<a href="login.php">注册账号</a></span><br><span class="ch"><a href="ch.php">修改密码</a></span></div></form>
</body></html>
judge.php(登录的后端代码)
<?php
$db_name = $_POST['db_name'];
$db_pass = $_POST['db_pass'];
if(!empty($db_name) && !empty($db_pass)){$coon = mysqli_connect('localhost',root','root','admin');//查询数据$sql_select = "SELECT db_name,db_pass FROM db_user WHERE db_name = '$db_name' AND db_pass = '$db_pass'";$ret = mysqli_query($coon,$sql_select);$row = mysqli_fetch_assoc($ret);if($db_name == $row['db_name'] && $db_pass == $row['db_pass']){header("location:panel.php");}else{echo "<script>alert('登录失败,用户名或密码不正确');</script>";}
}
?>
login.php(注册的前端代码)
<!DOCTYPE html>
<html><head><meta charset="utf-8"><title>注册界面</title><style>.home {text-align: center;font-weight: bold;}h2 {color: red;font-size: 40px;}.db_name,.db_pass {margin-bottom: 10px;font-size: 20px;}.submit,.reset {font-size: 20px;margin-bottom: 10px;}.re {margin-left: 50px;font-size: 20px;}.lo {margin-left: 50px;}.hint {color: red;}</style>
</head><body><h2>欢迎来到您的注册页面!</h2><!-- 使form表单中的内容发送到指定位置进行下一步操作(action="db.php")以post形式传入 --><form action="judge_login.php" method="POST"><div class="home"><div><span>账 号:<input type="text" required class="db_name" name="db_name" /></span><br><span>密 码:<input type="password" required class="db_pass" name="db_pass" /></span><br><span>确认密码:<input type="password" required class="db_name" name="db_pass_1"></span></div><div class="lo"><input type="submit" value="注册" class="submit" /><input type="reset" value="重置" class="reset" /></div><span class="hint">小提示:注册成功后会自动返回登录界面!</span><br><span class="re"><a href="re.php">返回登录</a></span><br></div></form>
</body></html>
judge_login.php(注册的后端代码)
<?php
$db_pass = $_POST['db_pass'];
$db_pass_1 = $_POST['db_pass_1'];//db_pass_1表示重复密码
$db_name = $_POST['db_name'];
if (!empty($db_pass) && !empty($db_pass_1)) {//连接数据库$coon = mysqli_connect('localhost', 'root', 'root', 'admin');//用于查询数据的语句$sql_re = "SELECT db_name FROM db_user WHERE db_name = '$db_name'";//用于执行SQL语句$ret = mysqli_query($coon, $sql_re);//从结果集取一行作为关联数组$rows = mysqli_fetch_assoc($ret);//判断该账号是否已经存在if ($db_name == $rows['db_name']) {echo "<script>alert('该账号已被注册,请重新输入!');</script>";}else{//判断两次密码是否相等if ($db_pass == $db_pass_1) {//插入数据的语句,用于将内容插入数据库的列中$sql_pw = "INSERT INTO db_user(db_name,db_pass) VALUES ('$db_name','$db_pass')";//执行SQL语句$row = mysqli_query($coon, $sql_pw);//关闭结果集,作用是释放资源mysqli_free_result($row);//提示用户注册成功echo "<script>alert('注册成功!');</script>";//返回登录界面,也代表注册成功header('location:re.php');} else {echo "<script>alert('两次密码不相同,请重新输入!');</script>";}}
}
ch.php(修改密码的前端界面)
<!DOCTYPE html>
<html>
<!-- 该界面是用户用来修改密码的界面 --><head><meta charset="utf-8"><title>修改密码</title><style>.home {text-align: center;font-weight: bold;}h2 {color: red;font-size: 40px;}.db_name,.db_pass,.db_newpass,.db_oldpass {margin-bottom: 10px;font-size: 20px;}.submit {font-size: 20px;margin-bottom: 10px;margin-left: 35px;}.hint {color: red;}.re {margin-left: 50px;font-size: 20px;}</style>
</head><body><h2>欢迎来到您的修改密码界面!</h2><form action="ch_db.php" method="POST" class="form"><div class="home"><div><span>账 号:<input type="text" required class="db_name" name="db_name" /></span><br><span>原 密 码:<input type="password" required class="db_pass" name="db_pass" /></span><br><span>新 密 码:<input type="password" required class="db_newpass" name="db_newpass" /></span><br><span>重复密码<input type="password" required class="db_newpass" name="db_repass" /></span></div><div><input type="submit" value="提交" class="submit" /><br></div><div><span class="hint">小提示:密码成功后会自动返回登录界面!</span><br><span class="re"><a href="index.php">返回登录</a></span></div></div></form>
</body></html>
ch_db.php(修改密码的后端代码)
<?php
$coon = mysqli_connect('localhost', 'root', 'root', 'admin');//这是判断修改密码的界面
$db_name = $_POST['db_name'];
$db_pass = $_POST['db_pass'];
$db_newpass = $_POST['db_newpass'];
$db_repass = $_POST['db_repass'];$sql_judge = "SELECT db_name,db_pass FROM db_user WHERE db_name='$db_name' AND db_pass = '$db_pass'";$row_judge = mysqli_query($conn,$sql_judge);$ret_judge = mysqli_fetch_assoc($row_judge);if($db_name == $ret_judge['db_name'] && $db_pass == $ret_judge['db_pass']){if($db_newpass == $db_repass && $db_pass != $db_newpass){$sql_newjudge = "UPDATE db_user SET db_pass = '$db_newpass' WHERE db_name = '$db_name'";mysqli_query($conn,$sql_newjudge);echo "<script>alert('密码修改成功!');window.location.href='index.php'</script>";}else{echo "<script>alert('两次密码不同或本次密码与之前密码相同,请返回重新验证');window.location.href='ch.php'</script>";}
}
else{echo "<script>alert('账号或密码错误,验证失败!');window.location.href='ch.php'</script>";
}
panel.php(登录成功后的界面)<!DOCTYPE html>
<html lang="en">
<head><meta charset="UTF-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width, initial-scale=1.0"><title>Document</title>
</head>
<body></body>
</html>
<?php
$coon = mysqli_connect('localhost','root','root','admin');echo "<title>我的账户</title>";$sql = "SELECT * FROM `db_user` ORDER BY id ASC";$rows = mysqli_query($coon,$sql);echo "登录成功!<br>";
?>
写的比较简单,如果有不好的地方还请各位师傅指教!
本文标签: 登录
版权声明:本文标题:登录 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1686747008a32369.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论