PDA

View Full Version : Super-simple php script request!



REEFˇ
July 16th, 2008, 10:19 PM
Hi,

I need flash to send a value from a var called "myVar" to a php file. Then, the PHP file should write "myVar=whatevervaluehere" into "myTxt.txt".

Ive searched but mostly get mysql stuff which I dont need. Thanks!

TheCanadian
July 16th, 2008, 10:28 PM
What AS version?

REEFˇ
July 16th, 2008, 10:31 PM
2.0, thanks for asking - i do need the actionscript.

craigphares
July 16th, 2008, 10:33 PM
If you're using AS3, you can do the following to get your data to PHP:

// import network classes
import flash.net.*;

// create your variables
var variables:URLVariables = new URLVariables();
variables.myVar = "whateverValueHere";
// construct your request
var request:URLRequest = new URLRequest("phpScript.php"); // replace the url of your php here
request.data = variables;
request.method = URLRequestMethod.POST; // use URLRequestMethod.GET to send the data via GET
// send the request
var loader:URLLoader = new URLLoader();
loader.load(request);

To retrieve the data in PHP:

<?php

$myVar = $_POST['myVar']; // use $_GET if sending data via GET

?>

craigphares
July 16th, 2008, 10:38 PM
Just saw that you need AS 2. To send the data in 2.0 do the following:

var result_lv:LoadVars = new LoadVars();
result_lv.onLoad = function(success:Boolean) {
if (success) {
// handle success
} else {
// handle error here
}
};
var send_lv:LoadVars = new LoadVars();
send_lv.myVar = "whateverValueHere";
send_lv.sendAndLoad("phpScript.php", result_lv, "POST"); // replace "POST" with "GET" to send via GET
};

REEFˇ
July 16th, 2008, 11:03 PM
Do you think you can modify the PHP to write to a txt file like stated in the first post?