PHP development of simple book background management system login complete code
In this section we create a login.php file to display the complete login function code
We created the style.css file earlier and put this CSS file in the same folder. Next, call the CSS style directly.
Introduce the database public file config.php.
<?php
require_once("config.php"); //引入数据库文件
?>
<?php
if($_POST["Submit"])
{
$username=$_POST["username"];
$pwd=$_POST["pwd"];
$code=$_POST["code"];
if($code<>$_SESSION["auth"])
{
echo "<script language=javascript>alert('验证码不正确!');window.location='login.php'</script>";
?>
<?php
die();
}
$SQL ="SELECT * FROM admin where username='$username' and password='$pwd'";
$rs=mysqli_query($link,$sql);
if(mysqli_num_rows($rs)==1)
{
$_SESSION["pwd"]=$_POST["pwd"];
$_SESSION["admin"]=session_id();
echo "<script language=javascript>alert('登陆成功!');window.location='admin_index.php'</script>";
}
else
{
echo "<script language=javascript>alert('用户名或密码错误!');window.location='login.php'</script>";
?>
<?php
die();
}
}
?>
<?php
if($_GET['tj'] == 'out'){
session_destroy();
echo "<script language=javascript>alert('退出成功!');window.location='login.php'</script>";
}
?>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>图书后台管理系统登陆功能</title>
<!-- 引入CSS样式 -->
<link rel="stylesheet" type="text/css" href="style.css"/>
</head>
<body>
<div id="top"> </div>
<form id="frm" name="frm" method="post" action="" onSubmit="return check()">
<div id="center">
<div id="center_left"></div>
<div id="center_middle">
<div class="user">
<label>用户名:
<input type="text" name="username" id="username" />
</label>
</div>
<div class="user">
<label>密 码:
<input type="password" name="pwd" id="pwd" />
</label>
</div>
<div class="chknumber">
<label>验证码:
<input name="code" type="text" id="code" maxlength="4" class="chknumber_input" />
</label>
<img src="verify.php" style="vertical-align:middle" />
</div>
</div>
<div id="center_middle_right"></div>
<div id="center_submit">
<div class="button"> <input type="submit" name="Submit" class="submit" value=" ">
</div>
<div class="button"><input type="reset" name="Submit" class="reset" value=""> </div>
</div>
<div id="center_middle_right"></div>
</div>
</form>
<div id="footer"></div>
</body>
</html>
new file
<?php
require_once("config.php"); //引入数据库文件
?>
<?php
if($_POST["Submit"])
{
$username=$_POST["username"];
$pwd=$_POST["pwd"];
$code=$_POST["code"];
if($code<>$_SESSION["auth"])
{
echo "<script language=javascript>alert('验证码不正确!');window.location='login.php'</script>";
?>
<?php
die();
}
$sql="select * from admin where username='$username' and password='$pwd'";
$rs=mysqli_query($link,$sql);
if(mysqli_num_rows($rs)==1)
{
$_SESSION["pwd"]=$_POST["pwd"];
$_SESSION["admin"]=session_id();
echo "<script language=javascript>alert('登陆成功!');window.location='admin_index.php'</script>";
}
else
{
echo "<script language=javascript>alert('用户名或密码错误!');window.location='login.php'</script>";
?>
<?php
die();
}
}
?>
<?php
if($_GET['tj'] == 'out'){
session_destroy();
echo "<script language=javascript>alert('退出成功!');window.location='login.php'</script>";
}
?>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>图书后台管理系统登陆功能</title>
<!-- 引入CSS样式 -->
<link rel="stylesheet" type="text/css" href="style.css"/>
</head>
<body>
<div id="top"> </div>
<form id="frm" name="frm" method="post" action="" onSubmit="return check()">
<div id="center">
<div id="center_left"></div>
<div id="center_middle">
<div class="user">
<label>用户名:
<input type="text" name="username" id="username" />
</label>
</div>
<div class="user">
<label>密 码:
<input type="password" name="pwd" id="pwd" />
</label>
</div>
<div class="chknumber">
<label>验证码:
<input name="code" type="text" id="code" maxlength="4" class="chknumber_input" />
</label>
<img src="verify.php" style="vertical-align:middle" />
</div>
</div>
<div id="center_middle_right"></div>
<div id="center_submit">
<div class="button"> <input type="submit" name="Submit" class="submit" value=" ">
</div>
<div class="button"><input type="reset" name="Submit" class="reset" value=""> </div>
</div>
<div id="center_middle_right"></div>
</div>
</form>
<div id="footer"></div>
</body>
</html>
Preview
Clear
- Course Recommendations
- Courseware download
The courseware is not available for download at the moment. The staff is currently organizing it. Please pay more attention to this course in the future~
Students who have watched this course are also learning
Let's briefly talk about starting a business in PHP
Quick introduction to web front-end development
Large-scale practical Tianlongbabu development of Mini version MVC framework imitating the encyclopedia website of embarrassing things
Getting Started with PHP Practical Development: PHP Quick Creation [Small Business Forum]
Login verification and classic message board
Computer network knowledge collection
Quick Start Node.JS Full Version
The front-end course that understands you best: HTML5/CSS3/ES6/NPM/Vue/...[Original]
Write your own PHP MVC framework (40 chapters in depth/big details/must read for newbies to advance)
















