所以我正在开发一个虚拟世界,我目前正在试图让login.php检查用户是否被禁用或未激活。如果用户被禁止,被禁止的列将显示“1”(如果未被禁止则为“0”。)如果用户的帐户被激活,则活动列将显示“1”(如果未激活,则为“0”。)我的as2发送post paramaters用户名并传递给login.php。 Login.php执行此操作:
<?php
$myServer = "localhost";
$myUser = "root";
$myPass = "";
$myDB = "game";
//connection to the database
$dbhandle = mysql_connect($myServer, $myUser, $myPass)
or die("Couldn't connect to SQL Server on $myServer");
//select a database to work with
$selected = mysql_select_db($myDB, $dbhandle)
or die("Couldn't open database $myDB");
// The response variable
$res = "res=KO";
// Check incoming data
if ($_POST['name'] != "" && $_POST['pass'] != "") {
// Retrieve all rows from the "user_name" and "password" columns from the "account_info" table
$result = mysql_query("SELECT username, password, active, banned FROM users")
or die(mysql_error());
}
//create a loop that continues until each row is called
while($row = mysql_fetch_array($result)) {
//check if client user name/password is the same as the row from database
if ($_POST['name'] == $row['username'] && $_POST['pass'] == $row['password'] && $row['active'] = '1' && $row['banned'] == '0') { //BE AWARE OF "" ''
// If they match, Ok, user found
$res = "res=OK";
break;
}
else if ($_POST['name'] == $row['username'] && $_POST['pass'] == $row['password'] && $row['active'] == '0' && $row['banned'] == '0')
{
$res = "res=unactive";
}
else if ($_POST['name'] == $row['username'] && $_POST['pass'] == $row['password'] && $row['banned'] == '1' && $row['active'] == '1' )
{
$res = "res=banned";
}
}
print $res;
?>
这是处理$ res的函数:
serverIn.onLoad = function(success)
{
if (success)
{
if (this.res == "OK")
{
sendLogin()
}
else if (this.res == "unactive")
{
var win:MovieClip = showWindow("errorWindow")
win.errorMsg.text = "Your account is not activated."
}
else if (this.res == "banned")
{
var win:MovieClip = showWindow("errorWindow")
win.errorMsg.text = "Your account is banned."
}
else
{
var win:MovieClip = showWindow("errorWindow")
win.errorMsg.text = "Incorrect username or password"
}
}
else
{
var win:MovieClip = showWindow("errorWindow")
win.errorMsg.text = "Connection failed"
}
}
两个文件都运行良好,之前一直工作,直到我添加了login.php的一部分来检查用户是否被禁止。所以这是我的问题:
我在数据库中更改了我的用户信息,以便我被禁止并激活。但是发送到swf的$ res是res = unactive并且使“User not active”窗口出现。当我被禁止并激活时,我希望“用户禁止”弹出窗口出现。
然后我改变它以便我不被禁止而且我很活跃。这让我感觉很好,就像它应该的那样。
我然后这样我就不会被禁止而且不活跃。当它不应该登录时。我希望“用户未激活”窗口出现,但事实并非如此。
答案 0 :(得分:2)
这可能很重要:
(PHP的第29行)
$row['active'] = '1'
这是将值设置为1,而不是将值设置为1。
$row['active'] == '1'
另外,请不要将用户凭据存储为纯文本!