Link to home
Start Free TrialLog in
Avatar of derrida
derrida

asked on

problem with login code AS3 with php

Hi
well i`m working on a simple login form. it send the username and password to the php file. this works great. in the php file i have an if statment which echo "ok" or "notok". and then an if statment in AS3 which checks if it got back "ok" or "notok".  the problem is: i always get "notok", i think i know why: the variable which store the returning value does not store it . hope i explained myself correctly:)

here is the php code:

$un = $_POST['username'];
$pass = $_POST['pass'];

if($un == "somename" && $pass == "somepass"){
echo "logged=ok";
}else{
echo "logged=notok";
}

obviously this is the first step before database. just checking good connection with flash.

and this is the AS3 code:




best regards

ron
private function packageAndSend ():void {
								
loginLoader = new URLLoader();
loginRequest = new URLRequest("http://localhost/loginWclass/login.php");
loginRequest.method = URLRequestMethod.POST;
loginLoader.dataFormat = URLLoaderDataFormat.TEXT;
loginVars = new URLVariables();
				
loginVars.username = log.username_txt.text;
loginVars.pass = log.password_txt.text;
				
loginRequest.data = loginVars;
				
trace(loginRequest.data);
				
loginLoader.load(loginRequest);
				
loginLoader.addEventListener(Event.COMPLETE , islogged);
				
				
}
			
			
private function islogged (e:Event):void {
trace(e.target);
	var logged:String ;
	if (logged == "ok") {
	trace("ok");
	}else{
	trace("notok");
		}
 
}

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of derrida
derrida

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Aneesh Chopra
problem is in function islogged

below is the updated islogged function
function islogged(e:Event):void {
	var loader:URLLoader = URLLoader(e.target);
	trace("completeHandler: " + loader.data);
 
	var vars:URLVariables = new URLVariables(loader.data);
	trace("The response is " + vars.logged);
 
	if (vars.logged == "ok") {
		trace("ok");
	} else {
		trace("notok");
	}
}

Open in new window

Excuse me,  isn't there an issue as well with the fact that the URLLoaderDataFormat is set to TEXT instead of VARIABLES?

DM