Solved

problem with login code AS3 with php

Posted on 2008-06-25
3
1,349 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

NAS Cloud Backup Strategies

This article explains backup scenarios when using network storage. We review the so-called “3-2-1 strategy” and summarize the methods you can use to send NAS data to the cloud

Question has a verified solution.

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

This is intended to introduce all collision detection principles in flash, their strengths, weaknesses and workarounds. The main method for Collision Detection in flash is using hitTestObject. But unless you'll be pushing rectangular shapes without …
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…
In this tutorial viewers will learn how to create a basic shape tween animation in Flash including shape hints for smooth animation Open a new document in Flash: Draw a shape: Select another frame (how long you want the tween to be): Right click and…
This Micro Tutorial will teach to how to utilize bit rate in Adobe Flash Media Live Encoder.

832 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