PHP development small forum tutorial - login to PHP page
This page is to compare the data we passed from the login page with the data in the database
If it is incorrect, the user will not be allowed to log in

The specific code is as follows
<?php
session_start();
header("Content-type:text/html;charset=utf-8");
$link = mysqli_connect('localhost','root','root','mybbs');//链接数据库
mysqli_set_charset($link,'utf8'); //设定字符集
$username=$_POST['username'];
$password=md5($_POST['password']);
if($username==''){
echo "<script>console.log('请输入用户名');location='" . $_SERVER['HTTP_REFERER'] . "'</script>";
exit;
}
if($password==''){
echo "<script>console.log('请输入密码');location='" . $_SERVER['HTTP_REFERER'] . "'</script>";
exit;
}
$sql="select id,username,password from member where username= $username"; //从数据库查询信息
$que=mysqli_query($link,$sql);
$row=mysqli_fetch_array($que);
if($row){
if($password !=($row['password']) || $username !=$row['username']){
echo "<script>console.log('密码错误,请重新输入');location='login.html'</script>";
exit;
}
else{
$_SESSION['username']=$row['username'];
$_SESSION['id']=$row['id'];
echo "<script>console.log('登录成功');location='index.php'</script>";
}
}else{
echo "<script>console.log('您输入的用户名不存在');location='login.html'</script>";
exit;
};
?>Because we have not registered yet, we cannot log in. Let’s create our registration page
new file
<?php
session_start();
header("Content-type:text/html;charset=utf-8");
$link = mysqli_connect('localhost','root','root','mybbs');//链接数据库
mysqli_set_charset($link,'utf8'); //设定字符集
$username=$_POST['username'];
$password=md5($_POST['password']);
if($username==''){
echo "<script>console.log('请输入用户名');'</script>";
exit;
}
if($password==''){
echo "<script>console.log('请输入密码');</script>";
exit;
}
$sql="select id,username,password from member where username= $username"; //从数据库查询信息
$que=mysqli_query($link,$sql);
$row=mysqli_fetch_array($que);
if($row){
if($password !=($row['password']) || $username !=$row['username']){
echo "<script>console.log('密码错误,请重新输入');location='login.html'</script>";
exit;
}
else{
$_SESSION['username']=$row['username'];
$_SESSION['id']=$row['id'];
echo "<script>console.log('登录成功');location='index.php'</script>";
}
}else{
echo "<script>console.log('您输入的用户名不存在');location='login.html'</script>";
exit;
};
?>
Preview
Clear
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)





![Getting Started with PHP Practical Development: PHP Quick Creation [Small Business Forum]](https://img.php.cn/upload/course/000/000/035/5d27fb58823dc974.jpg)










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~ 