PDA

View Full Version : Flash login w/password...angry..



Freddythunder
June 21st, 2003, 04:44 PM
Hello all-

I've been trying to get this working for about two days doing searches and trying tuts and ideas and them customizing them to what I want and I cant get the **************** thing to work.
Here's the deal:
1. I want to have a login page in flash that will take a user name and password,
2.throw it to a php file,
3.have the php file check for a match in mySQL and have that php file send back a var saying auth=1 (approved) or auth=0 (no dice),
4. Then have flash say "okay, auth==1, gotoAndPlay(secret stuff)" or "hey, auth==0, gotoAndPlay(no soup for you)" I mean it seams SO EASY!! RIGHT!!???

The php script that I've attached is one that does exactly what I want to have flash do. This script works in HTML!! Anybody wanna take a stab?

λ
June 21st, 2003, 04:53 PM
I think it might be easier to have a different order of execution... you could have the PHP script pull the usernames and passwords out of a database and print them.

Then the flash file would check if the username and password matched its list allowed names.

I have no idea how to implement this, as I havn't really got into PHP yet. I just think that that approach would be easier.

Freddythunder
June 21st, 2003, 04:54 PM
One more thing, there's a working HTML version here:
http://freddythunder.com/ucs/php/login.html

That way you can see how I'm posting to the php.

Name (first field - didn't label them, too angry) : testname
Password (second field) : testpass

good luck!!

Freddythunder
June 21st, 2003, 04:58 PM
Thanks for looking NJS! I actually wouldn't know how to print out everything from the database to Flash and make a list that way, I figure you would have to make an array for Flash to look at. I didn't see you post when I posted, but the HTML version basically looks for a row in the dbase with a matching name and password, if it exists, you win.

I'll keep that in mind if all else fails; however, then I would have to learn how to post an array of variable to Flash when I can't even get 1 in!! I believe that's my main problem is the communication between PHP and Flash..Boo...

For instance, at the end here:


if ( ! $auth ) {

header( 'WWW-Authenticate: Basic realm="Private"' );
header( 'HTTP/1.0 401 Unauthorized' );
echo 'Authorization Required.';
exit;

} else {

echo '<P>You are authorized!</P>';
}

?>

instead of having the headers redirect the HTML page, I want a variable set and read by flash like auth=1. That way, I can put an if/else loop checking auth and sending the user wherever.

eyezberg
June 21st, 2003, 05:05 PM
replace

} else {

echo '<P>You are authorized!</P>';
}
by

} else {

echo "&auth=$auth";
}
----------------------------
remarks!

if ( $num != 0 ) {
can be replaced by

if ( $num ) {

and you should close your mysql connection at the end of the script!!!

Freddythunder
June 21st, 2003, 05:37 PM
Thanks EYEZ!! Where's your footer? Anyhow; I tried something close to that, but not exactly. Will the one loadVariblesNum command on my button on the first frame of the movie pull back that 'auth' variable, or do I have to use LoadVars();? The tut on kirupa only sends a variable to a movieClip with a text box using 'this'. What if I just want to load a variable to use here and there in Flash? (In this case, only once, but in future projects I may have to use the var more than once).

Freddythunder
June 22nd, 2003, 12:32 AM
Alright...I'm so close I can smell it! and it smells good!! Eyes, I took your advice and closed the mysql session and changed that last statement. Now, I made a quick little movie to see if I could get it to work, and I cant. However, if you put in a working set (user/pass) and then run the php script rigth away, it will echo the correct thing in the browser - so I think I'm talking to it!! Now, getting the '&auth=1' back into flash, I think I'm having a problem...Please help me with this last thing and I promise to leave you guys alone for at least a week!! :P

http://freddythunder.com/ucs/php/flashlogin.fla
http://freddythunder.com/ucs/php/flashlogin.swf
http://freddythunder.com/ucs/php/flashlogin.php

eyezberg
June 22nd, 2003, 06:57 AM
i'm back in 2 weeks, good luck..

Freddythunder
June 22nd, 2003, 03:02 PM
No dice, but thanks for the try. You did give me a good idea to load the variables into an empty movieClip. I will continute to try - thanks anyway eyez!! (and put your footer back! I miss messing with it!!).

Anybody else got any ideas?? I'm all ears! :*(

R@b
June 23rd, 2003, 03:19 AM
Alright, I had a look at eyezberg his version and the thing with php is that it can be rather tricky into loading the variables into the textfields. Have you made a plain document where textField gets filled from your php? Anyhow I might have a good example for you for a nice login. But you will have to wait once I get home but I think I can help you out ;)

viva work! :geek:

Digitalosophy
June 23rd, 2003, 08:23 PM
freddy when i log in with a bad pw, it gets stuck

Freddythunder
June 24th, 2003, 01:38 AM
Hey Digital!

Yeah, that's half the prob. The other half of the prob is when you put in the correct stuff, it'll still get stuck.. My problem is getting the variable 'auth' from the PHP back into Flash. Flash is posting, but nothing's comming back. The cheese slid off the cracker. Any ideas?

Digitalosophy
June 24th, 2003, 04:18 PM
hey freddy...

i am by far no php expert but this is a script that display's my php news into my flash file


// PHP FILE
$title = ""; // I do this to tell me that $title is going to be a string.
for ($i=0; $i <$num_results; $i++){ // for loop
$row = mysql_fetch_assoc($result); // You know what this is
$title .= $row['date'] . "\r\n". $row['description'] . "\r\n";
}

print "title=".$title; //print it out so Flash can read it.
?>


then in my flash file, i have a textfield "title" which displays the info, by simply loading vars.

not sure if this will help but this is how i get my info into flash. how bout posting your php file, maybe we can intergrate the script.

Digitalosophy
June 24th, 2003, 05:14 PM
yea freddy i looked at your code, your not passing any data back to flash, that is the problem

Freddythunder
June 24th, 2003, 07:17 PM
Actually, I changed the last part of the code to what Eyezberg told me:


} else {

echo "&auth=$auth";
}

which is the same as what yours is. You can use print or echo and joint your string together with a '.' - I think still think the problem is in my flash movie and how I'm loading it in (or not loading it in, in this case).

Loading PHP to a txt box is easy. However, I'm trying to load in a variable that I can use at any time anywhere in the movie. That's what I need to do is try to load the answer into a text box without trying actions right away. I'm gonna do that, then edit this post to see if PHP is actually talking to flash or not.

Wish me luck!!

Freddythunder
June 24th, 2003, 08:20 PM
I won't edit, I take it back..

So, I added a text box and in the frames actions, I have this:


this.onEnterFrame = function() {
loadVariables("flashlogin.php", this, "POST");
if (_root.auth == "1") {
gotoAndPlay(5);
} else {
gotoAndPlay(4);
}
};
_root.crap = _root.auth;

Frame 5 says 'you're in' and frame 4 is a loop that goes back to the actions above.

HERE'S THE KICKER!! :scream: When you play it, it sends the info to PHP, gets into the loop, a fraction of a second later, flash pulls the variable from the PHP and pops it into the box (emphatically named 'crap'). SO, everything works, except Flash is ignoring the fact that auth==1 and should goto(5).. EEERRRRR!!
I've tried it with and without the quote marks around the 1, in case that caught your eye.

So, the PHP works, mySQL works, it's flash that isn't working. But why?? This is the question I ponder...

Digitalosophy
June 24th, 2003, 08:43 PM
hmm well as far as that i really can't help ya much. :( Your code looks right to me.

Jubba
June 25th, 2003, 11:53 AM
These files might help a bit.

here is a link to what it will look like:

http://www.bluefinatlantic.com/egTest/freddy.swf

if you enter "Jubba" for the user and "1234567" for the password

it will display granted. Anything else will say denied. The dynamic textbox is printed out from variables recieved from the PHP file.

Then you would just redirect depending on where they want to go.

Freddythunder
June 25th, 2003, 07:55 PM
Thank you Jubba, however, I need it tied to mySQL because it's for a website I'm designing. I believe I saw that same thing that you made in the forum somewhere in my research.

I'm going to make an HTML page for my client to add in names and passwords to the database so I won't have to rewrite the PHP each time they get a new client.

I don't know if you looked at my fla, but on that same frame is says _root.crap=_root.auth (crap is the text box) and it works, the variable is comming back correctly to Flash, but when I put it in an if/else statement in a loop, it doesn't work.

Ripping my hair out!!!http://freddythunder.com/test/hair.gif

Well, if anything, I'll just make a popup window and do that part in HTML. Quite honestly, the client would never know, nor care. If no one else has any ideas, I thank you all for your time and suggestions!!!

Digitalosophy
June 25th, 2003, 08:23 PM
freddy you still cant get it to go to frame 5?

Freddythunder
June 25th, 2003, 10:36 PM
Nooo!! Stupid thing!! Don't know why!! Should work!! Doesn't!! Auth==1, but...AAARRRRGHGGHGHHH!!!

Digitalosophy
June 25th, 2003, 10:39 PM
lol i feel your pain mang

R@b
June 27th, 2003, 10:56 AM
Hey Freddy, sorry for my super delay. I will be home in about 1 hour and I will upload a login script which i used some time ago. Hope it will help you.

:P

Freddythunder
June 27th, 2003, 01:56 PM
Cool!!

Clown Staples
June 29th, 2003, 01:58 PM
shouldn't it wait until the variables are loaded to check auth==1?

Freddythunder
June 29th, 2003, 07:39 PM
It's all part of the loop. Everytime it loops between those two frames, it does the loadVariables and checks if auth==1 - if it does, it's supposed to go to frame 5. As we have all found, the variable DOES come back to Flash correctly. If you go to the swf file and put in the test name and pass (testone and testtwo or testuser and testpass), there's a textbox that either shows a '1' for Flash saying 'Oh, okay, I got it' or nothing like nothing's being returned.

I have to check today, but someone at flash-db gave me a different as to use that isn't a loop; so I'll give that a try and let everyone know.

Again - thank you to everyone for helping me - this one really is a 'wicked pisser'.

Freddythunder
June 29th, 2003, 11:31 PM
Hello everyone involved - How are ya? I'm pretty good, my thing works now. Let me tell ya what I did.

First I want to thank njs12345, eyezberg, digitalosophy, Jubba, R@b, and Clownstaples for helping me through this trying time. I actually used ideas from all of you (except R@b - btw if you still have that login script, I still wouldn't mind seeing it).

The problem was the loop. An administrator at flash-db gave me three different flash5 and 6 AS that didn't work at all, but he did say at the end of his post what Clownstaples told me in his:
shouldn't it wait until the variables are loaded to check auth==1?
.......Ahh.....yeah?

I redid everything. I rewrote my own PHP script instead of using the augmented HTML version and redid the flash thing alltogether. You can check it out - attached.

Then my new working thing is here:
http://www.freddythunder.com/test/logintest.swf

Put in testone and testtwo or testname and testpass

Good times!! Thank you all again for spending time on my little prob - I can now put my footer back to normal
:beam:

Digitalosophy
June 29th, 2003, 11:43 PM
all right ! glad to see you got it working :)

CARNIC
December 6th, 2003, 03:59 AM
Originally posted by Freddythunder
Alright...I'm so close I can smell it! and it smells good!! Eyes, I took your advice and closed the mysql session and changed that last statement. Now, I made a quick little movie to see if I could get it to work, and I cant. However, if you put in a working set (user/pass) and then run the php script rigth away, it will echo the correct thing in the browser - so I think I'm talking to it!! Now, getting the '&auth=1' back into flash, I think I'm having a problem...Please help me with this last thing and I promise to leave you guys alone for at least a week!! :P

http://freddythunder.com/ucs/php/flashlogin.fla
http://freddythunder.com/ucs/php/flashlogin.swf
http://freddythunder.com/ucs/php/flashlogin.php

Hi Freddy,
I am interested to this modified version of the login files.
Can I download the file .fla and .php?
Thank you for your reply.

Best Regards.

Freddythunder
December 6th, 2003, 01:47 PM
Hello,

All the files you want for this are in a zip file here:

http://www.kirupa.com/developer/actionscript/authentication.htm

REEF·
December 8th, 2003, 07:18 PM
Never thought I'd see a PHP problem with Freddy...:P (j.k)...

Freddythunder
December 9th, 2003, 01:43 AM
This is (was) old school (in my mind), but, since you brought it up and we're adding to this post; let me through in a couple ¢s.

After this whole thing went down and I got it working, I wrote the tut on it with a working example. It can be seen here:
http://www.kirupa.com/developer/actionscript/authentication.htm

After that went up, there have been many thoughts on the tut. I've learned that using LoadVars() could be a better way to go. I've learned 10-fold with PHP since making that tut - and let me tell you, that's still an opening for learning, but a working model for sure! I hope those out there have enjoyed it; or at least learned from my mistakes. :D