我在这里有这个脚本:
<?php
//Tell the requester to output response as JSON
//header('Content-Type: application/json;charset=utf-8');
//POST information.
$name = $_POST['username'];
$pass = $_POST['password'];
$mysql_server = 'localhost';
$mysql_user = 'root';
$mysql_pass = '';
$mysql_dbname = 'test';
//Set up variables needed for middle-end
$return_code = 0;
$error_message = '';
//Connect to the Database
$conn = new mysqli($mysql_server, $mysql_user, $mysql_pass, $mysql_dbname);
if ($conn->connect_error)
{
//Return an error (in JSON format) that MySQL server wont connect
$return_code = -1;
$error_message = 'Failed to connect to MySQL: ' . $conn->connect_error;
}
else
{
//Query for a User/Pass match
$sqlquery = "SELECT ucid FROM test WHERE ucid = '" . $name . "' AND password = '" . hash('sha256', $pass) . "'";
$result = mysqli_query($conn, $sqlquery);
if (mysqli_num_rows($result) > 0)
{
//On Successful User/Pass
$return_code = 1;
}
elseif(mysqli_num_rows($result) == 0)
{
//On Failed User/Pass
$return_code = 0;
$error_message = 'Incorrect Username or Password';
}
else
{
//Something went wrong
$return_code = -1;
$error_message = 'You messed something up real good.';
}
}
基本上,你向它传递一个用户名和密码,然后脚本连接到一个 MySQL 服务器,并在它被 sha256 散列后执行用户名 + 密码的 SQL 查询。查询的重点是查看用户名+密码是否为有效组合。如果其中一个错误,则查询应显示 0 个结果,从而导致“用户名或密码不正确”消息
但是,当我运行脚本并回显结果时,显然没有通过:
<b>Notice</b>: Undefined variable: jsonResults in <b>C:\xampp\htdocs\alpha-test\db.php</b> on line <b>62</b><br />
null<br><br>return code = 0 and message: Incorrect Username or Password<br>Query Passed: SELECT ucid FROM test WHERE ucid = '' AND password = 'e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855'Username passed was: and Password passed was:
我不知道我做错了什么。
LEATH
慕雪6442864