php/mysqli 登录管理员/用户

时间:2021-07-26 10:10:13

标签: php mysqli passwords

我正在尝试为管理员和用户创建登录页面。我在其中创建了一个 db,其中 rol 为 1 或 0。1 = 管理员,0 = 普通用户。问题是我不知道如何告诉脚本 a= 理解 2 和 b 之间的区别。在不同的页面上使用该信息。我试过其他问题,但似乎没有一个对我有用

<?php
if (isset($_POST['log']) && isset($_POST['email']) && isset($_POST['wachtwoord'])){

        $c_email = bin2hex(htmlspecialchars($_POST['email']));
        $c_pass = bin2hex(htmlspecialchars($_POST['wachtwoord']));

        $sel_c = "SELECT * FROM users WHERE users_pass=UNHEX('$c_pass') AND users_email=UNHEX('$c_email')";

        $run_c = mysqli_query($conn, $sel_c);
        $check_customer = mysqli_num_rows($run_c);

        if($check_customer === 0){

        echo "<script>alert('Password or Email is incorrect!')</script>";
        exit();

        } else {
                $_SESSION['users_email']=$c_email;
                echo "<script>alert('login!')</script>";
                if($row['rol'] == '1'){
                    $_SESSION['isAdmin'] = true;
                }else{
                    $_SESSION['isAdmin'] = false;
                 }
                 if($_SESSION['isAdmin']){
                    //code for uploading pictuers ..
                    echo "<script>window.open('winkel.php','_self')</script>";
                }else{
                    echo "lol";
                    echo "<script>window.open('winkel.php','_self')</script>";
                }


        }
    }
?>

0 个答案:

没有答案