当尝试使用php和mysql登录此应用程序时,将Authorization failed显示该应用程序中使用的错误。阅读php_error.log时显示:
[05.05.2019 03:31:51 UTC] PHP注意:未定义的索引:结果在第43行的/Applications/MAMP/htdocs/iReporter/api.php中[05-May-2019 03:31:51 UTC] PHP警告:count():参数必须是在第43行的/Applications/MAMP/htdocs/iReporter/api.php中实现Countable的数组或对象
登录功能
//login API
function login($user, $pass) {
// try to match a row in the "login" table for the given username and password
$result = query("SELECT IdUser, username FROM login WHERE username='%s' AND pass='%s' limit 1", $user, $pass);
//Line 43
if (count($result['result'])>0) {
// a row was found in the database for username/pass combination
// save a simple flag in the user session, so the server remembers that the user is authorized
$_SESSION['IdUser'] = $result['result'][0]['IdUser'];
// print out the JSON of the user data to the iPhone app; it looks like this:
// {IdUser:1, username: "Name"}
print json_encode($result);
//edit
var_dump($result);
} else {
// no matching username/password was found in the login table
errorJson('Authorization failed');
}
}
该应用程序用于让用户无缝登录,但突然停止工作,而无需对代码进行任何更改。即使未更改的备份文件也收到相同的错误。如何更改代码以允许用户成功登录?
更新:index.php。应用程序访问功能的主文件
switch ($_POST['command']) {
case "login":
login($_POST['username'], $_POST['password']);
break;
解决了
更改了iOS应用程序,以将密码而不是固定密码发布到数据库,因为它正在创建错误。
料青山看我应如是
红颜莎娜