Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/62.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 mysql中的登录会话_Php_Mysql_Session - Fatal编程技术网

Php mysql中的登录会话

Php mysql中的登录会话,php,mysql,session,Php,Mysql,Session,这是我在登录页面中的代码。我需要只允许数据库中的用户登录。用户可以是管理员,可以访问我网站中的某些链接。因此其他人无法访问我已将管理员分配给我的角色id为R2 用户可以查看除StaffReport之外的所有我的报告…因此,如果我是管理员,我将使用管理员用户名和密码 这是我在login.php上的代码 <?php session_start(); require_once("mysqlconn.php"); $dbconn = mysql_connect($ho

这是我在登录页面中的代码。我需要只允许数据库中的用户登录。用户可以是管理员,可以访问我网站中的某些链接。因此其他人无法访问我已将管理员分配给我的角色id为R2 用户可以查看除StaffReport之外的所有我的报告…因此,如果我是管理员,我将使用管理员用户名和密码 这是我在login.php上的代码

<?php

    session_start();

    require_once("mysqlconn.php");

    $dbconn = mysql_connect($hostname, $username, $password) or 
    die('Could not connect: ' . mysql_error());


    mysql_select_db($database, $dbconn);

    $uusername= $_POST['uusername'];
    $upassword= $_POST['upassword'];

    // build query
    $qry = "Select * from Users where u_username='$uusername' and " .
        "u_password=PASSWORD('$upassword')";

    // execute query
    $result = mysql_query($qry) or die('Query failed: ' . mysql_error());

    if(mysql_num_rows($result)==1)
    {


        $row = mysql_fetch_assoc($result);          

        .
        $_SESSION['userno'] = $row['user_id'];
        $_SESSION['roleno'] = $row['role_id'];

        header("Location: ./index.php"); 

        // stop execution of this page
        exit;
    }
    else
    {

        header("Location: ./LoginForm.php"); 

        exit;
    }

    mysql_close($dbconn);

?>

哇。SQL注入、会话固定和XSS漏洞都在同一段代码中!更不用说它没有做它应该做的一件事了。也许你应该添加一些调试来代替重定向。也许有两个jhon的密码相同,所以这不会通过:如果(mysql_num_rows($result)==1),也许它会将你重定向到index.php,index.php会将你重定向回login.php(我们不知道index.php的代码)
<?php
    // start the session - this has to be done in all scripts that use $_SESSION array
    session_start();    
    DEFINE("ADMIN_ROLE", "R2");
    // function to check if the user has logged in. If user has loged in then this function
    // returns a true
    function Has_Session()
    {
        if(!isset($_SESSION['userno']) or 
            $_SESSION['userno'] == "")
        {
            return false;
        }
        else
        {
            return true;
        }
    }

    // Declare cleaning function 
    function clean_it ($string_variable)
    { 
        $string_variable = addslashes(trim($string_variable)); 

        return $string_variable; 
    } 

    function IsAdministrator()
    {
        if(isset($_SESSION['roleid']) AND 
            $_SESSION['roleid'] == ADMIN_ROLE
        {
            return true;
        }
        else
        {
            return false;
        }
    }

    function printErrorMessage($message)
    {
        echo "<center><table id='form-table'><th>Access Error</th>" .
            "<tr><td><b>$message</b></td></tr></table></center>";

    }


?>