亚洲国产日韩欧美一区二区三区,精品亚洲国产成人av在线,国产99视频精品免视看7,99国产精品久久久久久久成人热,欧美日韩亚洲国产综合乱

PHP development small forum tutorial login-2

Create the login.php file

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

logphp.jpg

The specific code is as follows

<?php
session_start();
header("Content-type:text/html;charset=utf-8");
$link = mysqli_connect('localhost','root','root','mybbs');//鏈接數(shù)據(jù)庫
mysqli_set_charset($link,'utf8'); //設(shè)定字符集
$username=$_POST['username'];
$password=md5($_POST['password']);
    if($username==''){
        echo "<script>alert('請輸入用戶名');location='" . $_SERVER['HTTP_REFERER'] . "'</script>";
        exit;
    }
    if($password==''){
        echo "<script>alert('請輸入密碼');location='" . $_SERVER['HTTP_REFERER'] . "'</script>";
        exit;
    }
$sql="select id,username,password from member where username= $username";      //從數(shù)據(jù)庫查詢信息
$que=mysqli_query($link,$sql);
$row=mysqli_fetch_array($que);
if($row){
    if($password !=($row['password']) || $username !=$row['username']){
        echo "<script>alert('密碼錯(cuò)誤,請重新輸入');location='login.html'</script>";
        exit;
    }
    else{
        $_SESSION['username']=$row['username'];
        $_SESSION['id']=$row['id'];
        echo "<script>alert('登錄成功');location='index.php'</script>";
    }
}else{
    echo "<script>alert('您輸入的用戶名不存在');location='login.html'</script>";
    exit;
};
?>


Continuing Learning
||
<?php session_start(); header("Content-type:text/html;charset=utf-8"); $link = mysqli_connect('localhost','root','root','mybbs');//鏈接數(shù)據(jù)庫 mysqli_set_charset($link,'utf8'); //設(shè)定字符集 $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"; //從數(shù)據(jù)庫查詢信息 $que=mysqli_query($link,$sql); $row=mysqli_fetch_array($que); if($row){ if($password !=($row['password']) || $username !=$row['username']){ echo "<script>console.log('密碼錯(cuò)誤,請重新輸入');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; }; ?>
submitReset Code