嗨,我有一个从外部脚本检查MYBB的用户名和密码的类登录,它似乎工作,但有小问题。对于不同的用户,结果返回所有用户的相同uid和email (mybb_users表中的第一个uid和email)。请如何解决这个问题。谢谢你的帮助。
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
);
}
}
}
}
像下面这样改变你的脚本并尝试一下。
return array( 'uid' => $row['uid'] ,
'mail' => $row['email'],
'user' => $username
);