所以,我正在用Flash,PHP编写应用程序,并在两者之间进行通信,我正在使用AMFPHP。我是PHP的新手,我只是用它来存储和检索数据库中的数据。首先,这是我登录系统的代码:
<?php
class loggin {
function logginfunc($user123, $pass123)
{
$user123;
$pass123;
// Connect to Database //
$host2 = "host";
$username2 = "username";
$password2 = "password";
$db2 = "db";
$con2 = mysqli_connect($host2,$username2,$password2,$db2) or die("Can not connect to Server.");
//Injection Prevention
$user123 = stripslashes($user123);
$pass123 = stripslashes($pass123);
$user123 = mysqli_real_escape_string($con2, $user123);
$pass123 = mysqli_real_escape_string($con2, $pass123);
if($user123 == "" || $pass123 == "")
{
return "Please fill in all the information!";
}
//Check to see if the username AND password MATCHES the username AND password in the DB
else
{
$query2 = mysqli_query($con2,"SELECT * FROM users WHERE username = '$user123' and password = '$pass123'") or die("Can not query DB.");
$count2 = mysqli_num_rows($query2);
if($count2 == 1){
//YES WE FOUND A MATCH!;
return "5";
}
else{
return "Wrong";
}
}
}
function hello() {
return "$user123";
}
}
?>
这是我的AS3代码
//连接//
var gw2:NetConnection = new NetConnection();
var responder2:Responder = new Responder(onResult2);
var responder3:Responder = new Responder(onResult3);
addEventListener(Event.ENTER_FRAME, loginenters);
function loginenters(e:Event) {
gw2.connect("http://teach-ware.org/amfphp/gateway.php");
}
function onResult2(responds23:Object) {
trace(responds23);
}
function onResult3(responds33:Object) {
wronginfo.visible = true;
wronginfo.text = "Hello " + responds33;
}
// Visiibilty //
hometext.visible = true;
feedbacktext.visible = true;
wronginfo.visible = false;
// Listeners //
login2.addEventListener(MouseEvent.CLICK, loginclick2);
function loginclick2(e:MouseEvent) {
gw2.call("loggin.logginfunc", responder2, usernamelogin.text, passlogin.text);
gw2.call("loggin.hello", responder3);
}
所以,我首先调用loginfunc函数来确定用户名是什么,然后调用hello函数并将文本放在onResult3函数中。所以,它返回的只是“Hello”而没有“Hello(用户名)”,这就是我想要做的。我知道问题是显而易见的,但在PHP上是一个菜鸟我还不知道所有的事情。所以,再次对不起是一个完整的菜鸟,但如果她能找到问题,那将是一个救生员。