Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/271.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/8/mysql/72.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/SQLite安全性_Php_Sqlite - Fatal编程技术网

PHP/SQLite安全性

PHP/SQLite安全性,php,sqlite,Php,Sqlite,我对整个PHP/SQLite安全游戏非常陌生;我不知道如何防范注入攻击、基于PHP_自身的威胁等等。有人能检查一下我的55行登录页面,指出我可能存在的安全漏洞吗?我会非常感激的 <?php // Begin Redirector ****************************************************************************************** if (isset($_COOKIE["session"])) { header(

我对整个PHP/SQLite安全游戏非常陌生;我不知道如何防范注入攻击、基于PHP_自身的威胁等等。有人能检查一下我的55行登录页面,指出我可能存在的安全漏洞吗?我会非常感激的

<?php
// Begin Redirector ******************************************************************************************
if (isset($_COOKIE["session"])) { header("location:http://pagesnap.tk/"); }
// End Redirector ******************************************************************************************

else
{
?>
    <html>
        <head>
            <title>Sign In - PageSnap</title>
        </head>
        <body>
            <h1>PageSnap</h1>
            <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
                <input name="username" type="text" placeholder="Username "/>
                <br />
                <input name="password" type="password" placeholder="Password" />
                <br />
                <br />
                <input name="signin" type="submit" value="Sign In" />
            </form>
        </body>
    </html>
<?php
    if ($_POST["signin"]) // If Form Is Submitted
    {
        // Variables
        $username = $_POST["username"];
        $password = $_POST["password"];
        $password = hash("sha512", $password);

        // Database Connection
        $database = new PDO("sqlite:database.sqlite");

        // Entry Finder
        $result = $database -> query("SELECT COUNT (*) FROM accounts WHERE username = '$username' AND password = '$password'");

        // Success
        if ($result -> fetchColumn() > 0)
        {
            $id = $database -> query("SELECT id FROM accounts WHERE username = '$username' AND password = '$password'");
            $id = $id -> fetchColumn();
            setcookie("session", "$id", time()+3600);
            header("location:http://pagesnap.tk/");
        }

        // Failure (Entry Not Found)
        else
        {
            echo "You have entered your username or password incorrectly.";
        }
    }
}
?>
多谢各位

您应该使用ctype_*或filter_var函数过滤所有输入:

 if( ctype_alnum( $_POST["username"]  )  ) {

      $username = $_POST["username"];

 } else {

     //error

 }
所有其他输入的do

你应该使用事先准备好的语句

您应该使用绑定参数

在这种情况下,您应该转义所有输出:

     setcookie("session", htmlentities( $id ), time()+3600);

顺便说一句,如果你想试试的话,我的网站的URL是pagesnap.tk。永远不要相信用户提交的信息。像这样盲目地将信息推送到查询中正是获得SQL注入的方式。至少你正在使用pdo,但是你需要绑定你的变量。试试代码修改谢谢!我很感激你提供的信息。