Login background function ideas for PHP development

The realization of the function requires the concatenation of PHP codes. Before writing PHP code, you need to clarify your ideas, otherwise the code will not be able to start. Let's first explain the flow of ideas, as shown in the figure:

1_(Y9AW($LQQE96F@JRTN1N.png

According to the idea, let’s take a look at the code:

<?php
session_start();
header("content-type:text/html;charset=utf-8");
//连接数据库
$link = mysqli_connect("localhost","root","root","regedit");
if (!$link) {
    die("连接失败: " . mysqli_connect_error());
}
if(isset($_POST)){
    //用户名不能为空
    if(!$_POST['username']){
        echo('用户名不能为空');
        return;
    }
    //密码不能为空
    if(!$_POST['password']){
        echo('密码不能为空');
        return;
    }
    //判断验证码是否填写并且是否正确
    if(!$_POST['code']){
        echo('验证码不能为空');
        return;
    }else if($_POST['code']!=$_SESSION['VCODE']){
        echo('验证码不正确');
        return;
    }  
    $sql="select username,password from form where username = '{$_POST['username']}' and password='{$_POST['password']}'";
    $rs=mysqli_query($link,$sql); //执行sql查询
    $row=mysqli_fetch_assoc($rs);
    if($row) { // 用户存在;
        if ($username == $row['username'] && $pwd == $row['password']) { //对密码进行判断。
            echo "登陆成功,正在为你跳转至后台页面";
            //header("location:index.php");
        }
    }else{
        echo "账号或密码错误" . "<br/>";
        echo "<a href='login.html'>返回登陆页面</a>";
    }
}

The first thing is to connect to the database, because the login account and password are all in the database, and then start to check whether the account password verification code has been entered. judge. Then use the sql statement to query the database to see if the entered value exists in the database. If

exists and is correct, you can log in successfully. Otherwise, "Account or password error" is output and you log in again.

Continuing Learning
||
<?php session_start(); header("content-type:text/html;charset=utf-8"); //连接数据库 $link = mysqli_connect("localhost","root","root","regedit"); if (!$link) { die("连接失败: " . mysqli_connect_error()); } if(isset($_POST)){ //用户名不能为空 if(!$_POST['username']){ echo('用户名不能为空'); return; } //密码不能为空 if(!$_POST['password']){ echo('密码不能为空'); return; } //判断验证码是否填写并且是否正确 if(!$_POST['code']){ echo('验证码不能为空'); return; }else if($_POST['code']!=$_SESSION['VCODE']){ echo('验证码不正确'); return; } $sql="select username,password from form where username = '{$_POST['username']}' and password='{$_POST['password']}'"; $rs=mysqli_query($link,$sql); //执行sql查询 $row=mysqli_fetch_assoc($rs); if($row) { // 用户存在; if ($username == $row['username'] && $pwd == $row['password']) { //对密码进行判断。 echo "登陆成功,正在为你跳转至后台页面"; //header("location:index.php"); } }else{ echo "账号或密码错误" . "<br/>"; echo "<a href='login.html'>返回登陆页面</a>"; } }
submitReset Code