Login and password problem

  • maario
  • Novice
  • Novice
  • User avatar
  • Posts: 17

Post 3+ Months Ago

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
  • Posts: ?
  • Loc: Ozzuland
  • Status: Online

Post 3+ Months Ago

  • IceCold
  • Guru
  • Guru
  • User avatar
  • Posts: 1254
  • Loc: Ro

Post 3+ Months Ago

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.
  • maario
  • Novice
  • Novice
  • User avatar
  • Posts: 17

Post 3+ Months Ago

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
  • Posts: 1254
  • Loc: Ro

Post 3+ Months Ago

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.
  • maario
  • Novice
  • Novice
  • User avatar
  • Posts: 17

Post 3+ Months Ago

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
  • Posts: 17

Post 3+ Months Ago

Anyone?...
  • spork
  • Brewmaster
  • Silver Member
  • User avatar
  • Posts: 6251
  • Loc: Seattle, WA

Post 3+ Months Ago

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.  
  • maario
  • Novice
  • Novice
  • User avatar
  • Posts: 17

Post 3+ Months Ago

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
  • Posts: 17

Post 3+ Months Ago

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

:?: :!: :?
  • spork
  • Brewmaster
  • Silver Member
  • User avatar
  • Posts: 6251
  • Loc: Seattle, WA

Post 3+ Months Ago

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.
  • Bogey
  • Genius
  • Genius
  • Bogey
  • Posts: 8388
  • Loc: USA

Post 3+ Months Ago

Are the letters in "ko" uppercase or lowercase?
  • maario
  • Novice
  • Novice
  • User avatar
  • Posts: 17

Post 3+ Months Ago

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 10 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
 
 

© 1998-2014. Ozzu® is a registered trademark of Unmelted, LLC.