嗨,我有一个类登录,用于从外部脚本检查 MYBB 的用户名和密码,它似乎工作但有小问题。对于不同的用户,结果为所有用户返回相同的 uid 和电子邮件(mybb_users 表中的第一个 uid 和电子邮件)。请问如何解决这个问题。谢谢你帮助我。
class Login
{
function CheckLogin( $username, $password )
{
$MySQL_Host = "localhost";
$MySQL_User = "root";
$MySQL_Pass = "";
$MySQL_DB = "";
$tbl_name = "";
// Connect to server and select databse.
mysql_connect("$MySQL_Host", "$MySQL_User", "$MySQL_Pass") or die(mysql_error());
// echo "Connected to MySQL<br />";
mysql_select_db("$MySQL_DB") or die(mysql_error());
// echo "Connected to Database<br />";
$sql="SELECT * FROM $tbl_name WHERE username='$username'";
$result=mysql_query($sql);
if( $result == false )
return false;
// fwrite($fh, $result);
// fclose($fh);
$count=mysql_num_rows($result);
// If result matched $username and $password, table row must be 1 row
if($count==1){
$row = mysql_fetch_assoc($result);
global $mybb;
if (md5(md5($row['salt']).md5($password)) == $row['password']){
return array( 'uid' => $mybb->user['uid'] ,
'mail' => $mybb->user[ 'email' ],
'user' => $username
);
}
}
}
}