PHP 개발을 위한 로그인 배경 기능 아이디어

기능을 구현하려면 PHP 코드를 연결해야 합니다. PHP 코드를 작성하기 전에 아이디어를 명확히 해야 합니다. 그렇지 않으면 먼저 그림과 같이 아이디어의 흐름을 설명할 수 없습니다.

1_(Y9AW($LQQE96F@JRTN1N.png

아이디어에 따라 다시 시작해 보겠습니다. 코드를 살펴보세요:

<?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>";
    }
}

로그인 계정과 비밀번호가 모두 데이터베이스에 있으므로 가장 먼저 데이터베이스에 연결한 다음 계정 여부를 판단하기 시작합니다. 비밀번호 인증번호가 입력되었습니다. 그런 다음 sql 문을 사용하여 데이터베이스에 입력한 값이 존재하는지 확인하고, 해당 값이 존재하고 맞다면 "잘못된 계정 또는 비밀번호"를 출력하고 다시 로그인할 수 있습니다.

지속적인 학습
||
<?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>"; } }
회사 소개 부인 성명 Sitemap
PHP 중국어 웹사이트:공공복지 온라인 PHP 교육,PHP 학습자의 빠른 성장을 도와주세요!