| Home | Tutorials | Forums | Articles | Blogs | Movies | Library | Employment | Press | Buy templates |
|
|
#1 |
|
Registered User
Join Date: Feb 2001
Location: Levittown, N.Y.
Posts: 25
|
Does anyone know of a php file that can be used to pass variables from a flash swf to a txt file on the server?
Flashlite |
|
|
|
|
|
#2 |
|
Flash'a'holic
|
Havent seen a php one, might be an idea for me to code one and distribute it but anyway, there is a perl version at:
http://www.kessels.com/flashdb ![]() |
|
|
|
|
|
|
|
|
#3 |
|
Administrator
Join Date: Nov 2000
Location: Australia
Posts: 8,625
|
It's almost exactly the same with PHP. I used PHP to store my variables for FlashCHess ( http://flashchess.cjb.net if it's even still up
) in temporary text files on the server.My code was something like: Code:
<?php $fd = fopen("tempFile.txt", "w");
fwrite($fd, "blah blah blah blah");
fclose($fd); ?>
![]() I trigerred this running using a LoadMovie command from Flash and GET as my variable post method (int he background so the user stays in the Flash file and doesn't see the PHP page ever). For more info try http://www.php.net/manual/en/function.fwrite.php Cheers Jesse
__________________
Cheers Jesse Stratford ActionScript.org Cofounder Email: presented in this way to stop spam-bots: My email is composed of my first name (jesse) followed by my last name (stratford) followed by @ followed by actionscript.org Please don't email or PM me Flash questions, that's what the Forums are for! ![]() Please don't rely on me reading my PMs either. Email me about important stuff. |
|
|
|
|
|
#4 |
|
Flash'a'holic
|
only one problem with that jesse, ampersands are taken as the start of new variables, hence sending the text so that it can be read back into flash is not possible with your script
|
|
|
|
|
|
#5 |
|
Administrator
Join Date: Nov 2000
Location: Australia
Posts: 8,625
|
Nah nah it is. See I used that script orriginally for just that purpose. Here's the orriginal:
Code:
<?php $fd = fopen("$session.txt", "w");
fwrite($fd, "turn=$turn&captured=$captured&piece=$piece");
fclose($fd); ?>
)it outputs plain text with ampersands which I read back into the other user's computer.. taht how I got interaction between 2 comps over the net ![]() Cheers Jesse
__________________
Cheers Jesse Stratford ActionScript.org Cofounder Email: presented in this way to stop spam-bots: My email is composed of my first name (jesse) followed by my last name (stratford) followed by @ followed by actionscript.org Please don't email or PM me Flash questions, that's what the Forums are for! ![]() Please don't rely on me reading my PMs either. Email me about important stuff. |
|
|
|
|
|
#6 |
|
Registered User
Join Date: Feb 2001
Location: Levittown, N.Y.
Posts: 25
|
I really don't know much about php/cgi scripting. Basically I have a slight idea as to configuring if there is a readme file to show me but otherwise I'm a real beginner. Jesse, on this php script fo yours, what exactly needs to be configured, and how?
Flashlite |
|
|
|
|
|
#7 |
|
Flash'a'holic
|
yes but jesse if you do this:
<?php $fd = fopen("$session.txt", "w"); fwrite($fd, $variables); fclose($fd); ?> then use: loadVariablesNum("thephpscript.php?variables=hello &variable2=tester",0) php recognizes the variable called "variable 2" as a new variable for the script, not a part of "variables" |
|
|
|
|
|
#8 |
|
Administrator
Join Date: Nov 2000
Location: Australia
Posts: 8,625
|
Ahh right Guru, I see your point. Oh well, the problem never arose for me
![]() FlashLite, ok let's look at the script: Code:
<?php $fd = fopen("tempFile.txt", "w");
fwrite($fd, "turn=$turn&captured=$captured&piece=$piece");
fclose($fd); ?>
Tells the server we're using PHP. opens a file 'tempFile.txt' for writing to. (ifthe file doesn't exist, create it). Line 2: writes to our open file whatever is within the quotes. Line 3: closes the file. The main bit you need to change is the second line... OK so let's say you have a flash movie with a text field into which a user types their name. then you want to output their name to this PHP script (and thus into a text file on the server). We're goign to have to pass your variables from Flash into the PHP script which is done in this way: loadVariablesNum ("thephpscript.php", 0, "GET"); This can be on a button or a keyframe or whatever. Doing it this way means it happens without the user being taken from flash using GetURL is also possible but it would mean the user is taken out of the flash file. Now we've specified the GET method for passing our variables to the script. So all we need to do is tell the PHP file the name of the variable we want it to write out to the text document. Variables in PHP are preceeded by the dollar sign ($) so if we wanted to write out the value of variable 'name' into a text file, our PHP would be: fwrite($fd, "$name"); It's that easy. if you wanted to write it out so it could be read back into flash later in the form: name=TheName you would do this: fwrite($fd, "name=$name"); Not hard huh? For more info checkout http://www.php.net The manually is really very easy. Note this will only work on a webserver which supports PHP so it wont work on your local computer HDD Cheers Jesse
__________________
Cheers Jesse Stratford ActionScript.org Cofounder Email: presented in this way to stop spam-bots: My email is composed of my first name (jesse) followed by my last name (stratford) followed by @ followed by actionscript.org Please don't email or PM me Flash questions, that's what the Forums are for! ![]() Please don't rely on me reading my PMs either. Email me about important stuff. |
|
|
|
|
|
#9 |
|
Registered User
Join Date: Feb 2001
Location: Levittown, N.Y.
Posts: 25
|
Thanks a lot. It is fairly simple. Now what is you want to be able to append the text file so u can add a series of users??
Flashlite |
|
|
|
|
|
#10 |
|
Administrator
Join Date: Nov 2000
Location: Australia
Posts: 8,625
|
Replace the w with an a for 'append'.
http://www.php.net/manual/en/function.fopen.php It's all there in the manual. Cheers Jesse
__________________
Cheers Jesse Stratford ActionScript.org Cofounder Email: presented in this way to stop spam-bots: My email is composed of my first name (jesse) followed by my last name (stratford) followed by @ followed by actionscript.org Please don't email or PM me Flash questions, that's what the Forums are for! ![]() Please don't rely on me reading my PMs either. Email me about important stuff. |
|
|
|
![]() |
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| passing variables to flash - too long? | babagadude | Server-Side Scripting | 2 | 06-03-2004 02:52 PM |
| passing Variables to a SWF file with GET Method | Faycal | ActionScript 1.0 (and below) | 1 | 09-16-2003 10:29 AM |
| using variables in external text file while running *.exe | dartagnan324 | Projectors and CDs | 1 | 08-07-2003 05:14 AM |
| Problems passing string variables? | rsomers | ActionScript 1.0 (and below) | 0 | 03-17-2003 10:29 PM |
| Can we load variables from external file? | tuyle | ActionScript 1.0 (and below) | 3 | 12-12-2002 08:02 AM |