Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

problem with login code AS3 with php

Posted on 2008-06-25
3
Medium Priority
?
1,352 Views
Last Modified: 2013-11-11
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

0
Comment
Question by:derrida
3 Comments
 
LVL 1

Accepted Solution

by:
derrida earned 0 total points
ID: 21863278
ok i fixed the problem myself. (hate it when i come with the answer just after i post the question:)

solution: the AS3 if statement check to see the returned data, and it got back "logged=ok" and not "ok". the same when its "notok". so the if statement should check for the whole returning value;

hope it somehow help somebody:)

ron
0
 
LVL 34

Expert Comment

by:Aneesh Chopra
ID: 21863343
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

0
 
LVL 8

Expert Comment

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

DM
0

Featured Post

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I come across a lot of question about how to access things in the document class from a movieclip, or accessing something from a movieclip in the document class. It took me a while to figure this out but once I did it makes life so much easier. …
Sometimes you know that one object has a specific child in it, but you can't find the child. This happened to me when I was trying to code some actionScript to make a toolbar work with its embedded buttons.  My partner had created the toolbar usi…
The goal of the tutorial is to teach the user how to how to record live broadcast.
The goal of the tutorial is to teach the user how to select which audio input to use. Once you have an audio input plugged into the laptop or computer, you will go into the audio input settings and choose which audio input you want to use.
Suggested Courses

916 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question