Solved

problem with login code AS3 with php

Posted on 2008-06-25
3
1,350 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

MS Dynamics Made Instantly Simpler

Make Your Microsoft Dynamics Investment Count  & Drastically Decrease Training Time by Providing Intuitive Step-By-Step WalkThru Tutorials.

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. …
Recently, I was asked to recommend a tracking system to be implemented on a clients website. As the entire site was built on flash, my first thought was to suggest custom built tracking system. However, our company at that point of time didn't h…
The goal of the tutorial is to teach the user how to use the auto adjust feature and what the different options do. When your video is not working right you can choose the auto adjust feature to help choose your settings.
This Micro Tutorial will teach to how to utilize bit rate in Adobe Flash Media Live Encoder.

688 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