Login and password problem

  • maario
  • Novice
  • Novice
  • User avatar
  • Joined: Nov 09, 2006
  • Posts: 17
  • Status: Offline

Post November 23rd, 2007, 5:47 am

I'm trying this but it don't work.

I know just a little more than nothing about php, so i believe the problem resides in there.

ActionScript part:

stop();
var user_input = "";
var pass_input = "";
login_button.onRelease = function() {
var users:LoadVars = new LoadVars();
users.username = user_input.text;
users.password = pass_input.text;
users.onLoad = function(success) {
if (users.login == "ok") {
gotoAndStop("OK");
} else {
gotoAndStop("NOTOK");
}
};
users.sendAndLoad("users.php", users, "POST");
};


The obscured PHP part: :roll:

$users = array("teste"=>"teste", "teste2"=>"teste2", "teste3"=>"teste3");
if(isset($_POST['username'])) {
$pass = $_POST['password'];
$user = $_POST['username'];
if($users[$user] == $pass) { echo "login=ok"; }
else { echo "login=notok"; }
}




Thanks for any help.

Mário[/b]
  • Anonymous
  • Bot
  • No Avatar
  • Joined: 25 Feb 2008
  • Posts: ?
  • Loc: Ozzuland
  • Status: Online

Post November 23rd, 2007, 5:47 am

  • IceCold
  • Guru
  • Guru
  • User avatar
  • Joined: Nov 05, 2004
  • Posts: 1254
  • Loc: Ro
  • Status: Offline

Post November 27th, 2007, 12:18 am

First of all, in sendAndLoad method, you need another variable of LoadVars type. Second, it's better to declare both of the variables outside of the function, otherwise their scope will end after the function is executed.
i.e.:
Code: [ Select ]
stop();

var users:LoadVars = new LoadVars();
var phpResponse:LoadVars = new LoadVars();

login_button.onRelease = function()
{
    users.username = user_input.text;
    users.password = pass_input.text;
    users.sendAndLoad("users.php", phpResponse, "POST");
}

phpResponse.onLoad = function(success)
{
    if (phpResponse.login == "ok")
    {
        gotoAndStop("OK");
    }
    else
    {
       gotoAndStop("NOTOK");
    }
}
  1. stop();
  2. var users:LoadVars = new LoadVars();
  3. var phpResponse:LoadVars = new LoadVars();
  4. login_button.onRelease = function()
  5. {
  6.     users.username = user_input.text;
  7.     users.password = pass_input.text;
  8.     users.sendAndLoad("users.php", phpResponse, "POST");
  9. }
  10. phpResponse.onLoad = function(success)
  11. {
  12.     if (phpResponse.login == "ok")
  13.     {
  14.         gotoAndStop("OK");
  15.     }
  16.     else
  17.     {
  18.        gotoAndStop("NOTOK");
  19.     }
  20. }

I'm not sure why you declare var user_input = ""; var pass_input = ""; if you already have two text fields named like that.
Also, strange as it seems, the php part looks very ok, the actionscript part was buggy.
“True mastery transcede any particular art. It stems from mastery of oneself - the ability, developed throgh self-discipline, to be calm, fully aware, and complety in tune with oneself and the surroundings. Then, and only then, can a person know himself. ”
  • maario
  • Novice
  • Novice
  • User avatar
  • Joined: Nov 09, 2006
  • Posts: 17
  • Status: Offline

Post November 27th, 2007, 2:27 am

Thanks once again.

The login variable in php always return the value "undefined"... So this still don't work.

There's not a sintaxe error, or something stupid like that, in php?
I'm using this on a server that, for sure, supports it...

Thanks.
  • IceCold
  • Guru
  • Guru
  • User avatar
  • Joined: Nov 05, 2004
  • Posts: 1254
  • Loc: Ro
  • Status: Offline

Post November 29th, 2007, 1:48 pm

what you could do to make sure the communication works.
in the php script just write this code:
Code: [ Select ]
<? echo "&login=notok&"; ?>

I had some problems before getting variables from php if i only use varName=something, so place it between "&" sign.
Then use the script from my previous post, and see if it works.
“True mastery transcede any particular art. It stems from mastery of oneself - the ability, developed throgh self-discipline, to be calm, fully aware, and complety in tune with oneself and the surroundings. Then, and only then, can a person know himself. ”
  • maario
  • Novice
  • Novice
  • User avatar
  • Joined: Nov 09, 2006
  • Posts: 17
  • Status: Offline

Post December 4th, 2007, 3:05 am

Hi.

There's progress on the way and there's still hope...

Ok, now they communicate with each other. Thanks.

Now the problem is that, the login var, always returns to flash with the value "ko"...
Any problem with the array...?! It should return the value "ok" as i put the right login and pass... But don't... Always "ko".
  • maario
  • Novice
  • Novice
  • User avatar
  • Joined: Nov 09, 2006
  • Posts: 17
  • Status: Offline

Post December 11th, 2007, 4:46 am

Anyone?...
  • spork
  • Brewmaster
  • Silver Member
  • User avatar
  • Joined: Sep 22, 2003
  • Posts: 6134
  • Loc: Seattle, WA
  • Status: Offline

Post December 11th, 2007, 11:24 pm

You're PHP is pretty jumbled. Give this a try:

PHP Code: [ Select ]
 
$users = array(
 
    "user1" => "pass1",
 
    "user2" => "pass2",
 
    "user3" => "pass3" );
 
 
 
if( isset( $_POST['username'] ) )
 
{
 
    $user = $_POST['username'];
 
    $pass = $_POST['password'];
 
}
 
 
 
 
 
if( $users[$user] == $pass )
 
{
 
    echo 'Login succeeded!';
 
}
 
else
 
{
 
    echo 'Login failed!'; }
 
}
 
 
  1.  
  2. $users = array(
  3.  
  4.     "user1" => "pass1",
  5.  
  6.     "user2" => "pass2",
  7.  
  8.     "user3" => "pass3" );
  9.  
  10.  
  11.  
  12. if( isset( $_POST['username'] ) )
  13.  
  14. {
  15.  
  16.     $user = $_POST['username'];
  17.  
  18.     $pass = $_POST['password'];
  19.  
  20. }
  21.  
  22.  
  23.  
  24.  
  25.  
  26. if( $users[$user] == $pass )
  27.  
  28. {
  29.  
  30.     echo 'Login succeeded!';
  31.  
  32. }
  33.  
  34. else
  35.  
  36. {
  37.  
  38.     echo 'Login failed!'; }
  39.  
  40. }
  41.  
  42.  
The Beer Monocle. Classy.
  • maario
  • Novice
  • Novice
  • User avatar
  • Joined: Nov 09, 2006
  • Posts: 17
  • Status: Offline

Post December 12th, 2007, 3:14 am

Hi.
Thanks for your help.

I've tryed but it still don't work. Login variable still always return with 'ko' value, instead of 'ok'...

Let's assume that the AS and PHP code are right.
Server where i'm trying this supports PHP.

What could be happening for this still don't work...? Can you imagine anything?
(sorry my bad english. hope you understand...)

Thanks for all.
  • maario
  • Novice
  • Novice
  • User avatar
  • Joined: Nov 09, 2006
  • Posts: 17
  • Status: Offline

Post December 17th, 2007, 9:34 am

Buáááááá...! :cry:

:?: :!: :?
  • spork
  • Brewmaster
  • Silver Member
  • User avatar
  • Joined: Sep 22, 2003
  • Posts: 6134
  • Loc: Seattle, WA
  • Status: Offline

Post December 17th, 2007, 9:41 pm

The problem must be somewhere else in your code. I don't see any "ko" string in any code you've posted.

Have you searched your files for "ko"?
Are you printing out the correct variable?

Try tracing the values in your variables as your program progresses and see if the source of the error can be pinpointed.
The Beer Monocle. Classy.
  • Bogey
  • Bogey
  • Genius
  • User avatar
  • Joined: Jul 14, 2005
  • Posts: 8212
  • Loc: USA
  • Status: Offline

Post December 17th, 2007, 10:50 pm

Are the letters in "ko" uppercase or lowercase?
"Bring forth therefore fruits meet for repentance:" Matthew 3:8
  • maario
  • Novice
  • Novice
  • User avatar
  • Joined: Nov 09, 2006
  • Posts: 17
  • Status: Offline

Post December 18th, 2007, 3:22 am

Oh! Sorry. I didn't post my last try .

Here my php file:
PHP Code: [ Select ]
$users  =  array(
 
        "user1"  =>  "pass1",
 
        "user2"  =>  "pass2",
 
        "user3"  =>  "pass3"  );
 
 
 
if(  isset(  $_POST['username']  )  )
 
{
 
        $user  =  $_POST['username'];
 
        $pass  =  $_POST['password'];
 
}
 
 
 
 
 
if(  $users[$user]  ==  $pass  )
 
{
 
        echo "&login=ok&";
 
}
 
else
 
{
 
        echo "&login=ko&";  }
 
}  
  1. $users  =  array(
  2.  
  3.         "user1"  =>  "pass1",
  4.  
  5.         "user2"  =>  "pass2",
  6.  
  7.         "user3"  =>  "pass3"  );
  8.  
  9.  
  10.  
  11. if(  isset(  $_POST['username']  )  )
  12.  
  13. {
  14.  
  15.         $user  =  $_POST['username'];
  16.  
  17.         $pass  =  $_POST['password'];
  18.  
  19. }
  20.  
  21.  
  22.  
  23.  
  24.  
  25. if(  $users[$user]  ==  $pass  )
  26.  
  27. {
  28.  
  29.         echo "&login=ok&";
  30.  
  31. }
  32.  
  33. else
  34.  
  35. {
  36.  
  37.         echo "&login=ko&";  }
  38.  
  39. }  


That's it. As i put the right or wrong login and pass, the 'login' variable always return 'ko' value.

If you have any interest in see the AS code, here he are:

Code: [ Select ]
stop();
var users:LoadVars = new LoadVars();
var phpResponse:LoadVars = new LoadVars();
login_button.onRelease = function() {
    users.username = user_input.text;
    users.password = pass_input.text;
    users.sendAndLoad("users.php", phpResponse, "POST");
};
phpResponse.onLoad = function(success) {
    trace(phpResponse.login); // Always tracing me with 'ko'
    if (phpResponse.login == "ok") {
        gotoAndStop("OK"); // a virgin place!
    } else {
        gotoAndStop("NOTOK");
    }
};
  1. stop();
  2. var users:LoadVars = new LoadVars();
  3. var phpResponse:LoadVars = new LoadVars();
  4. login_button.onRelease = function() {
  5.     users.username = user_input.text;
  6.     users.password = pass_input.text;
  7.     users.sendAndLoad("users.php", phpResponse, "POST");
  8. };
  9. phpResponse.onLoad = function(success) {
  10.     trace(phpResponse.login); // Always tracing me with 'ko'
  11.     if (phpResponse.login == "ok") {
  12.         gotoAndStop("OK"); // a virgin place!
  13.     } else {
  14.         gotoAndStop("NOTOK");
  15.     }
  16. };


Just one more question: is there any tracing option in php, so that i could follow the values of $user and $pass variables as the code go on?

Hey...thank you very much.
:wink:

Post Information

  • Total Posts in this topic: 12 posts
  • Users browsing this forum: No registered users and 35 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum
 
 

© 2011 Unmelted, LLC. Ozzu® is a registered trademark of Unmelted, LLC.