View Full Version : Passing Variables from Flash to PHP
djones
03-15-2004, 10:14 AM
I have a Flash intro with a login box. I know php pretty well but not actionscript. I have a username text field and a password text field, both have the vars labled username and password. I have tried the loadvars class on my submit button to pass the variables from flash to my php login script but it's not working.
I know my php login script works because I still have a html login form that works. Any help would be greatly appreciated. I have search these forums and found nothing thus far that works.
snapple
03-15-2004, 12:16 PM
You've done a search on loadVars() and found nothing that works, are you sure?
Regards, snapple
djones
03-15-2004, 03:53 PM
I was given this code to try, but the submit buttom does nothing until I change the "svObj.sendAndLoad" to "getURL" and then the browser only returns this in the URL box: http://www.mysite.com/test.php?svObj=pw%3Dtest%26un%3Dtest
Here's my current AS code:
submit.onRelease = function(){
svObj = new LoadVars(); // send object
svObj.un = this._parent.username.text;
svObj.pw = this._parent.password.text;
svObj.sendAndLoad("myLoginScript.php","_blank","POST");
}
This does not work. I've even tried a simple passing of a first name variable to a test.php that only prints the first name. That doesn't even work. Please help somebody. I can not quit.
butterbur
03-15-2004, 04:23 PM
You need to pause while waiting for the returned vars
submit.onRelease = function(){
svObj = new LoadVars(); // send object
svObj.un = this._parent.username.text;
svObj.pw = this._parent.password.text;
svObj.pw.onLoad = function(success) {
if (success) {
//what to do when script gets data back
}
};
svObj.sendAndLoad("myLoginScript.php",svObj,"POST");
}
Regards
BB
submit.onRelease = function(){
svObj = new LoadVars(); // LoadVars object
svObj.un = this._parent.username.text; //new var "un"
svObj.pw = this._parent.password.text; // new var "pw"
// sending the 2 vars to myLoginScript.php and getting the echo in the object svObj
svObj.sendAndLoad("myLoginScript.php", svObj, "POST");
}
When you are doing a sendAndLoad, you need to give the Object that will receive the echo of your script. It's not, as you done, to set up in which window it will be call (no need, it's a script hé).
in your php file
$name = $_POST['un'];
$pwd = $_POST['pw'];
//your script to check
correct?echo "&check=true&":echo "&check=false";
So in your svObj you will receive A VAR CONATAINING A STRING (ALWAYS STRING). Accessing like:
if (svObj.check=="true"), or if you are inside the svObj like eg for the onLoad method:
svObj.onLoad = function (success) {
if(success) {
if(check=="true") {
//log successfull
} else {
//warn wrong!
}
}
This is it... :)
Héhé.. I'm too slow... :) And the as tag still doesn't work WHYYYYYYYYYYYYYYYYYYYY
djones
03-15-2004, 05:47 PM
I don't need it to return any values, after the login...it's all php from there. Thank you for all your help.
so just use load methos...
not sendAndLoad...
djones
03-15-2004, 06:04 PM
Ok here is my updated AS, when I publish the movie my submit button does nothing. Excuse my AS noobness.
submit.onRelease = function(){
svObj = new LoadVars();
svObj.username = this._parent.username.text;
svObj.password = this._parent.password.text;
// sending the 2 vars to test.php and getting the echo in the object svObj
svObj.load("test.php", svObj, "POST");
}
It is on the same frame as the textareas and the submit button
ok could you send us your sample + you php script...
Then be able to debug...
C ya... ;)
And I done an error myself when telling you to use load only...
It's send and not load... (oops)
But anyway...
Gimme your fla and php script...
djones
03-15-2004, 06:31 PM
Here is the .fla (MX 2004). Layer near top labled "loginbox"
http://www.newelementdesigns.com/nemain5.fla
(allow a few minutes, I'm uploading now)
This is the test.php file... just to see if the variables are getting passed.
<?
// Recieving the variables.
$username = $_POST['username'];
$password = $_POST['password'];
// printing out the variables
print "Your name is ". $username . ".<br>";
?>
The test site URL is http://www.newelementdesigns.com/nemain.html
I can't download the fla... :(
And btw when using sendAndload send or load method, even if you are doing echo or print on your page, it will do nothing on your browser. I mean it's a script not a page.
if you want to test via echo on a page, use getURL method...
Waiting for your fla.. :)
Still...
Access forbidden!
You don't have permission to access the requested object. It is either read-protected or not readable by the server.
If you think this is a server error, please contact the webmaster.
Error 403
Ok anyway.
I done a little sample for you.
fla + little php script to show you how it's working... :)
C a mate... ;)
djones
03-15-2004, 07:31 PM
sorry it took a while to upload..slow upload speed. I'm actually at the office where the server is now. You should be able to download, but it's kinda big, so it may take a few minutes.
Have you seen the sample I sent?
djones
03-15-2004, 07:51 PM
Yes I have. Thank you. I'm trying to move completely to my php scripts after the user has enterd a username and password. The first script it will goto is my authenticate script to see if they exist in the MySQL databse and if they do it takes them to the members only section all in php.
All I need is to pass the username and password variables on to my php scripts just like if it were an HTML login form. I have not been successful and that's why I started the test.php so see why it's not happening.
djones
03-15-2004, 08:22 PM
Yes I have. Thank you. I'm trying to move completely to my php scripts after the user has enterd a username and password. The first script it will goto is my authenticate script to see if they exist in the MySQL databse and if they do it takes them to the members only section all in php.
All I need is to pass the username and password variables on to my php scripts just like if it were an HTML login form. I have not been successful and that's why I started the test.php so see why it's not happening.
So now it should be ok...
Just use the way I show you... :)
If you need help after this, just tell me and willf ix your fla. Cause the better way to learn is trying to do by itself... :)
I can't help it...lol
Dlding the fla to fix it...
but 42 mo heavy... Ouch... !
djones
03-15-2004, 09:18 PM
At this point all I want to see is a username or password pass to a php and print that username on the screen in php. As long as I see flash pass a variable to php, I'll be ok.
djones
03-15-2004, 09:20 PM
Shall I cut that frame out and paste it into a smaller movie for you to download/see? I will.
djones
03-15-2004, 09:25 PM
http://www.newelementdesigns.com/logintest.fla
The AS is on the submit button now.
K...
If you want to print on php page don't use LoadVars object but getURL method instead.
Told above that LoadVars was for script. I mean you are not able to laod a page. Just exec what's inside it... :)
Dlding the other fla too :)
on (release){
this.username = this._parent.username.text;
this.password = this._parent.password.text;
getURL("test.php","_blank", "POST");
}
use this for your case then...
Godd luck mate... ;)
djones
03-15-2004, 10:17 PM
We are getting closer. It now prints "Your name is undefined."
Go here and see. Just enter a name no password need at this time.
http://www.newelementdesigns.com/nemain5.html
CyanBlue
03-15-2004, 10:34 PM
Lemme butt in for a sec if you guys don't mind... :)
Yo, xxlm... Can you rephrase this for me??? ;)If you want to print on php page don't use LoadVars object but getURL method instead.Hey, djones... Can you post the content of the 'test.php' file??? :)
djones
03-15-2004, 10:39 PM
This is the test.php file. I just want to see the variables pass. As soon as I see it done I will send the username and password to my login scripts.
<?
$username = $_POST['username'];
$password = $_POST['password'];
print "Your name is ". $username . ".";
?>
CyanBlue
03-15-2004, 11:02 PM
Hm... I was really confused at work today with this darn GET/POST stuff and this is basically doing the same thing...
This works on my end...on (release)
{
this.username = this.username_txt.text;
this.password = this.userpass_txt.text;
getURL("http://localhost/djones/sendData.php", "_blank", "GET");
}<?php
// sendData.php
$username = $_GET['username'];
$password = $_GET['password'];
print "Your name is ". $username . ".";
?>
Thx cyan...
I was begining to think (lol) that I was wrong but no...
Ouf...
C ya... ;)
djones
03-15-2004, 11:11 PM
That works, it will show the username and password in the browsers URL box.
CyanBlue
03-15-2004, 11:18 PM
Well... Here is the reason WHY I asked you for some explanation...
I've had long battle with the LoadVars() and getURL() along with the GET/POST at work today... :(
Basically... The Flash movie is embedded into the ASP page and Flash makes a call with either LoadVars() or getURL()... LoadVars only send out the data to the ASP page when I use send() function, yet sendAndLoad() function does not work... Tried GET/POST with no success... send() function works, but I cannot use it because it opens up a new window... If there was a way to specify the window to open with the send() function, I'd be happy to use it because basically I needed to 'refresh' the page as a result of the ASP call... :(
So, the next one was to fiddle with the getURL() function... It took very long time to move onto the getURL() from LoadVars()... :(
getURL() did send out the variables fine and I was able to specify the _self to 'refresh' the window...
BUT, I just don't get it WHY sendAndLoad() function did not do the job... I was able to see that ASP page actually gets data from the Flash, yet it fails to refresh the screen... It was very long morning... :(
djones
03-15-2004, 11:19 PM
Guys.....it works now. I changed the GET(s) to POST and all is good. OK..so who has paypal, cos I'm paying someone.
freddycodes
03-15-2004, 11:25 PM
Now I will butt in for a second. Wouldn't it better to use sendAndLoad so your php script can check if the user is valid, and if they are, you can then send them to the next page and if not display an error, instead of having to send them back to the page with the flash movie? Why else are you even using flash for the login form?
Also loadvars.send() will work just as good if not better than getURL, since you can encapsulate outgoing vars in one object instead of sending everything in the current scope.
CyanBlue
03-15-2004, 11:30 PM
Yup... Totally agreed with freddycodes... Come to think of it, I have not tried to use load() function at work... I just thought that load() just 'load' the value from the external script... Maybe I'll try that tomorrow if I am not too busy... Thanks... :)
freddycodes
03-15-2004, 11:31 PM
Jason,
There is no reason why sendAndLoad can't be used with ASP?
Did you try to manually set the contentType?
You want to post any of the asp code? And the flash code? To do the LoadVars stuff?
Cyan --> Can't you target the window? Are you sure???
From MM help:
my_lv.send(url [,target, method])
Yeah right freddycodes you are right. Byut look from the begining. I post a sample doing the check and action if correct. But it was not what he want.
Just print something easily on a page. That's why I show this SIMPLE method.. :)
C ya... ;)
freddycodes
03-15-2004, 11:34 PM
Yep you can target other windows, you can use the html standard ones like _top, _self, _blank, _parent
Or a named one, and all other targets to that window will open in that window.
Like
loadvars.send("somepage.asp", "mywindowname", "POST");
I'm sure he done this lol. But I'm almost sure too there is a bug somewhere... :)
freddycodes
03-15-2004, 11:38 PM
There always bugs, for instance when using Debug > Test Movie, the POST method does not work.
So go on Bug thread and put this one... :)
Hope that a updater (like the one for Dreamweaver) will be avaible soon :) :)
CyanBlue
03-15-2004, 11:47 PM
Thanks, freddycodes... That ASP page is out of my reach... and she doesn't seem to have no idea about that Flash interaction... If I ever get a chance to see the code again, I'll get the copy of it... (It's done in C# though... and it looked very complex on my bare eyes...)
AND, I must been very sleepy this morning... I just THOUGHT that I cannot specify the windowName when I use LoadVars()... As a matter of fact, my wife woke me up early by kicking me off of the bed... :(
Thanks guys... Gotta hit the sack... Good night!!! :)
LoL
I know those kind of day, when your brain is foggy... :)
99 mate... ;)
freddycodes
03-16-2004, 03:07 AM
C# well then now we are talking ASP.NET not ASP. To different beasts literally.
You can definitely use sendAndLoad with ASP.NET no doubt about it. My guess is that it was outputting more than just the vars you needed. You should use the onData handler and trace the actual data coming back from the asp.net page.
abomination
04-11-2004, 05:25 AM
sorry to mis understand every post on here
I am building a flash for vbulletin 3.0
on a section of my site i wish flash to detect user name and display it in a welcome format I have created
so current flash has (Welcome: )in static text then a text box var =user
is next to it awaiting code to direct it to find user's name or if it is a guest.
also in the detecting part of it I have another flash that reacts one way or another if it is a guest or if its is a user loged in?
if someon could explain the steps I need to do to get this to work as I can not test it until finished
CyanBlue
04-12-2004, 01:42 PM
Hey, abomination... Let's step back for a sec and tell me this...
How do you detect if the user is a registered user or a guest on vB 3.0??? I am not talking about the Flash since Flash should call some PHP script to see if the user is in what stage... Do you know what it is???
As for the testing... If you know there is a PHP script that's coming with vB 3.0 that you can call to see the status of the membership, then call it via the browser directly... If there is none, you'd need to create one first and test to see if it works correctly... AFTER THAT, you go check on the Flash side... I think that's how it should be...
If you need to ask HOW you can detect if the user is registered or not, your best bet will be vB's support forum where you can get more help from the people who deal with the vB everyday... Just my 2 cents... :)
|
vBulletin® v3.8.4, Copyright ©2000-2009, Jelsoft Enterprises Ltd.