Checking variable from PHP

I just finished reading the thread posted by Freddythunder on his login and password script. I’ve had the same problem dealing with sending the user to a certain frame if after reading my php script, CheckLog=1. I tried using the ideas in that thread but I’m still having problems. Can anyone help, its driving me crazy!! Here is what I have:

frame 2
[AS]
//Load the php file
loadVariables(“checkCreated.php”, this, “POST”);
[/AS]

frame 3
[AS]
if (CheckLog == “1”) {
gotoAndPlay (7);
} else {
gotoAndPlay (5);
}
[/AS]

PHP


print "retVal=Login Complete&CheckLog=1";

loadVariables shouldn’t really be used for an login system, use LoadVars…try this:


sendlv = new LoadVars();
loadlv = new LoadVars();
loadlv.onLoad = function(success) {
if(success) {
if (this.CheckLog === "1") {
        gotoAndPlay (7);
} else {
        gotoAndPlay (5);
}
} else trace("cannot load script")
}
sendlv.sendAndLoad("checkCreated.php", loadlv, "POST");

let me know how that goes :slight_smile:

ok.

I’ve tried just about everything possible with my tiny skills and I’ve got the following problem.

I have my login page in a holder movieclip. In other words, it’s an external swf which is loaded inside the mainmovie. Sort of a pop up, you might say.

So, I think my login thingy, based on Freddythunder’s tut would work just fine, except I can’t get the checklog -variable into Flash, or at least into the correct timeline and I don’t know which timeline that would be, since _root doesn’t work and this.myClip doesn’t work and _parent doesn’t work.

Anyone with an idea?

I’m so tired, tired of waiting, tired of waiting for youuuu-u-uuh :smiley:

no, not for real, but seriously, does anyone have an idea on this:

I get variables from php into Flash and am able to use the to guide and command my Flash movie. I also get variable from Flash to php and they work like a charm, but…

I can not get my variables from php, into a loaded external movieclip inside a flashmovie. Why might that be?

I’ve tried every possible way I can imagine, do you know any ways to do this?

Please post and we’ll talk, ok?

how are you loading the external swf?

in the simple way, via “loadMovie”.

As I said, I tested the thingy on it’s own and it worked fine. When I load it into my main movie, it doesn’t work fine.

Got an idea, Ahmed?

hmm… i’ll be back with results shortly, im sure it can be done somehow :slight_smile:

hmmm… it works just fine for me, although i used my own methods… check it out here

http://24.141.60.208//eg/

http://24.141.60.208/eg.zip << source files

hope this kinda helps :slight_smile:

hmm. does it work just like that with MySQL? I’m sort of a noob, so…

Well I think it should work, it’s propably just in teh way we pass the variables on.

I’ll try it again and get back 2 u.

Thank for your help Friend:)

pulling the username/psw from a database or a textfile shouldn’t make any difference :slight_smile:

Whoa!! I’m sorry, I didn’t know about this thread!!

First, tripwire (and Ahmed) Make sure your case-sensitivity is correct between the php and Flash movie - that caused me hours of frustration - I just use all lowercase now.

Ahmed - I asked you in another thread what the difference is between using LoadVars and loadVariablesNum and you said ‘preference’, I don’t want to be telling people the wrong thing!!!

And Villek - I actually wrote that entire thing for a movie in a holder clip called ‘container’…I actually put it in use tonight. My lines of code in the PHP script are:


if ($num == 1){
	print "_root.container.status=You're in&checklog=1";
	} else {
	print "_root.container.status=Sorry, but your user name and password did not match a user name/password combination in our database.  Usernames and passwords are entered in from a different file.  Thank you for visiting test login script!!&checklog=2";
}
}
?>

…and it works like a charm.

I hope that helps…Let us know if it doesn’t!!

[edit]Also - tripwire - I also put that if statement in a repeating function because it may take up to a couple seconds to get your responce from the server. Like:


this.onEnterFrame = function() {
if (CheckLog == "1") {
        gotoAndPlay (7);
} else {
        gotoAndPlay (5);
}
};

Ahmed’s does the same thing, just in a different way. I will have to say, he is better than me with serverside stuff I’ve noticed!![/edit]

*Originally posted by Freddythunder *
Ahmed - I asked you in another thread what the difference is between using LoadVars and loadVariablesNum and you said ‘preference’, I don’t want to be telling people the wrong thing!!!
lol sorry, my bad :slight_smile:

Although it still is a preference, LoadVars is more functional since it has the onLoad event. If you’re loading large chunks of text into flash using loadVariablesNum and try to execute a function on it, big chance it won’t work… look at this:

echo 'myVar=some big value'

and then

loadVariablesNum("myscript.php", this)
trace(myVar)

Big change the script about would trace [FONT=courier new]undefined[/FONT], because the myVar might have not been fully loaded. with the LoadVars object, you would use the onLoad event, which ensures that trace is executed only once the text is fully loaded from the php script:

lv = new LoadVars()
lv.onLoad = function(success) {
if(success) {
trace(this.myVar)
}
}
lv.load("myscript.php")

LoadVars also loads the variable onto an object and not the timeline, that may or may not be an advantage. Another little thing is, you can use getBytesLoad() and getBytesTotal() with LoadVars, which you also could need when loading large chunks of data. You can also load data with no variables, try this:

echo 'this data is not contained within a variable';

and in flash:

lv = new LoadVars()
lv.onLoad = function() {
trace(unescape(this))
}
lv.load("myscript.php");

this would trace ‘this data is not contained within a variable’ (duh!)

If you want to learn more about LoadVars.send() and sendAndLoad(), check out jubba’s thread on sending variable to php, there’s an explaination on that =)

To sum it up, the LoadVars object is very similar to the XML object, only thing is it loads text as opposted to xml documents :slight_smile:

hope that helps! :slight_smile:

wow ya learn something every day. I didn’t know you could load in data with no assigned variable… :wink:

Me nither!! That’s good to know about that difference because if I were to make a guestbook in Flash, I shouldn’t (maybe cant) use loadVariablesNum, but I should use LoadVars, then I could put a load bar on it as well - that’s pretty cool.

I actually, in my hell of trying to get that login thing to work before, tried LoadVars, but needed the variable on the timeline like it is now. I think it’ll be okay because the amount of information is small in that tut.

I’ve got a question for you guys. I had a problem with that tutorial that you could right click the movie, get the menu then just forward your way through the login system. So in the tutorial, I told whoever to disable the menu. However, this little game on my footer uses PHP to save the high score and name to a text file (thank you Jubba, you tought me how to do that - even though you don’t know you did!!:P). Anyhow, it had the same problem - so I put in a blank frame with a movieClip on it that says:


on(load){
gotoAndStop(1);
}

That way if someone does forward, it’ll just shoot them back to the first frame. Whew…Now, my question. How do I add what I just said to my tutorial like in one of those yellow ‘notes’ boxes? Should I just put one together and mail it to Kirupa? Or should I just email Kirupa about it?

Lemme know - thanks again guys!!

if you have this line on your first frame:

Stage.showMenu = 0

the menu won’t actually show up :slight_smile:

Man, thank you Ahmed and everyone else too!!!

It seems that this thread got to be a nice source for some new info for many of us. Nice!!

I finally got that login thing working:)

I used Ahmed’s code in the Flash part and a MySQL db to store the usernames and passwords and it works fine via external mc’s.

The redirection parts work fine also and it works if the browser window is updated and what not etc.

Right now I’m pondering on the log out -issue. Can it work just so that I’ve got a log out button which tells my movie to go to it’s state before anyone logged in and tells the variable checklog that it’s value is now 0?

How would I do that?

I know it’s supposed to be required in FreddyThunders tutorials “back” -button, but I’m not quite sure my login -movie even requires that. It seems to work fine even if I don’t tell “checklog=0” in the back button.

Thank again guys, it sure is nice to get stuff working once in a while:)

I didn’t read freddythunder’s tutorial (only skimmed through it), and i dont have enough time to read it all, but do you set any cookies or sharedobjects? :slight_smile:

Me!? Setting cookies!? Setting shared objects!?

Man, I’m a noobie! :slight_smile:

Seriously though, no. I’m not settin’ nuthin’. I’ve not yet come to grasp the whole idea with using Flash with server side -coding. I just don’t understand it good enough when it comes to setting something from for example php and then fiddling at´around with that in flash.

In FreddyThunders tut there was an option if someone missspelled their pass or username.

Flash went to a spot with an errortext and a “back” -button.

Freddy’s tut adviced to make the checklog variable null when hitting the “back” -button ->

on(release) {

checklog=0;
this.gotoAndStop(1);

}


I thought that I’d use sessions to build the light CMS that I’m trying to build in Flash, but I’m up tp my ears in other work also so…

Btw, could you direct in the right place of knowledge when it comes to CMS and Flash. I mean administrating text, news (posting news, modifying old news, deleting news etc.) adding images etc. etc.

I’ve got some experiments of my own going, but they seem rather foolishly done so…

My tutrial was just a base auth system just for the use of learning to get PHP and Flash to talk and save data in MySQL. There’s no cookies or anything saved - however, if you stay in that same movie, checklog will always be ‘1’ after authentication so you could use that in other parts of your movie…that is until you don’t want them to. You could have a button that says logout that works just like the back button in the tutorial.

The best way to do sessions, I think, is with cookies because if you refresh the page or leave and comeback right away, you’ll still be logged in…However, thinking about it, I don’t really know of another way to do it.

I’m glad you got your login thing to work, Villek!!

Yeah, thanks to you, for making the tutorial, FT!!!

Umm, I don’t know if I’m on the right track here, but I think I’m not talking about cookies, but session variable which are stored in the code and checked on every pageload, if you work with non-Flash stuff.

Cookies are stored in the browsers cache, right?

Pls pls, sorrect me if I understood it alla wrong :-\

Now that we got started on this, could someone give a nutshell pack of info on sessions and cookies and the differences between them and using either in Flash?

Or maybe give out a link guiding to that info? I know these questions propably shouldn’t be here, but it’s reeeeeaally frustrating to search half the web, when people know where GOOD stuff lies.

Thanks and cheers!