Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/256.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/laravel/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
PHP多登录排名_Php_Mysql - Fatal编程技术网

PHP多登录排名

PHP多登录排名,php,mysql,Php,Mysql,因此,我有我正在编写的网站,在我的login.php中,这是源代码: <?php include "out_config.php"; session_start(); $username = mysql_real_escape_string($_POST['username']); $password = mysql_real_escape_string($_POST['password']); if(!$username) {

因此,我有我正在编写的网站,在我的login.php中,这是源代码:

<?php
    include "out_config.php";
    session_start();

    $username = mysql_real_escape_string($_POST['username']);
    $password = mysql_real_escape_string($_POST['password']);

    if(!$username) {
        header("Location: ../index?errormsg=nousername");
    }
    if(!$password) {
        header("Location: ../index?errormsg=nopassword");
    }       

    $sql = "SELECT * FROM users WHERE username='$username' and password='$password'";

    if($rankcheck == "Administrator" || $rankcheck == "Client") {
        $check = 1;
    }
    else {
        $check = 0;
    }

    if($_SERVER['REQUEST_METHOD'] == 'POST') {
        $result = mysql_query($sql);
        $count = mysql_num_rows($result);
            if($count==1 && $check == 1) {
                $_SESSION['username'] = $username;
                header("Location: ../home");
            }
            else {
                header("location: ../index?errormsg=invalidlogin");
            }
    }
?>
第一:我知道MySQL已经贬值了,但我想使用MySQL,因为我的主机支持MySQL比支持MySQLi/PDO更多

第二:你可以看到我的$rankcheck不起作用。我的排名检查行包含在out_config.php中,其源代码为:

<?php 
<Removed Details>
$connect = mysql_connect($host, $username, $password);
$selectdb = mysql_select_db($db);

$IP = getenv('REMOTE_ADDR');

$sql2 = mysql_query("SELECT `rank` FROM `users` where username='$user'");
if(isset($_SESSION['username'])) {
$user = $_SESSION['username'];
$rankcheck = mysql_result($sql2,0);
}
?>
你看,一切都很好P

现在的问题是,我试图只允许“管理员”和“客户”级别的人访问此区域,因此它将不起作用。我的数据库结构是:

它不授予用户和等待用户组成员的访问权限。但它甚至不允许管理员和客户端。我确信还没有密码加密


如果你能帮助我,那将是非常有帮助的

在包含out_config.php$username和$password的那一刻没有设置

更改为:

<?php
    session_start();

    $username = mysql_real_escape_string($_POST['username']);
    $password = mysql_real_escape_string($_POST['password']);

    include "out_config.php";

    if(!$username) {
        header("Location: ../index?errormsg=nousername");
    }
    if(!$password) {
        header("Location: ../index?errormsg=nopassword");
    }       

    $sql = "SELECT * FROM users WHERE username='$username' and password='$password'";

    if($rankcheck == "Administrator" || $rankcheck == "Client") {
        $check = 1;
    }
    else {
        $check = 0;
    }

    if($_SERVER['REQUEST_METHOD'] == 'POST') {
        $result = mysql_query($sql);
        $count = mysql_num_rows($result);
            if($count==1 && $check == 1) {
                $_SESSION['username'] = $username;
                header("Location: ../home");
            }
            else {
                header("location: ../index?errormsg=invalidlogin");
            }
    }
?>

如何获取$user in out_config.phpplaintext密码让我很难过:-@NicholasKing是对的,在存储密码时使用a。在login.phpIt中定义$user是通过action=inc/login>的形式吗?因此,一旦用户提交了其登录的数据,在您的示例中,首先包含out_config.php,然后从GET数组中填充变量$username和$password。你应该先设置一个变量,然后包括-看我的回答BTW:你真的应该改进你的代码-它绝对不安全SQL注入…我知道它是SQL注入的,这就是为什么我只是想学习SQL在使用mysql\u real\u escape\u字符串清除后,它在mysql中变得安全。我正在学习MySQLi编写的语句,因为PDO是我脑子里想不出来的。您提供的答案不起作用,我确实切换了它们,但仍然是一样的……:[另外,您能帮我将所有代码转移到MySQLi准备的语句中吗?