php bloack as3 after trying load variables in setinterval loop. i guess the title explain it all. actually i have flash widget that use URLLoader to grab some php variables and it works perfect but this urlloader is in setinterval loop that happens every 2 mins the problem is it work for several times well then after that php blocks the ip that loading the variables (using flash widget) and gives no response. i tried to search about this subject but found nothing especially that flash is outdated but i am using this flash in place which dont support except flash no js... idk what is the problem exactly but i got huge feeling its a server side issue and idk how to fix it. thought to share my issue here maybe someone can help. btw it blocks the ip of the user that been using the flash for long not for all but after 2-3 mins it unblocks the ip again and works again
btw when my ip is blocked by php i get this error as return by flash:
2101: The String passed to URLVariables.decode() must be a URL-encoded query string containing name/value pairs.
and by searching up found that this means the flash got nothing back from php request.
the as3 code is as simple as that:
submit_btn.addEventListener(MouseEvent.CLICK, btnDown);
function btnDown(event:MouseEvent):void {
var variables:URLVariables = new URLVariables();
var varto:URLRequest = new URLRequest("http://url/dir/script.php");
varto.method = URLRequestMethod.POST;
varto.data = variables;
var varLoader:URLLoader = new URLLoader;
varLoader.dataFormat = URLLoaderDataFormat.VARIABLES;
varLoader.addEventListener(Event.COMPLETE, completeHandler);
variables.somecode = "code";
varLoader.load(varto);
function completeHandler(event:Event):void{
var Var1fromphp = event.target.data.var1ofphp;
var Var2fromphp = event.target.data.var2ofphp;
from1_txt.text = Var1fromphp;
from2_txt.text = Var2fromphp;
trace("traced:" + event.target.data);
}
}
thanks and appreciate all the replies/support
found the problem wasnt php/server side its all about encoding then decoding the url for the variables cuz some vars had "&" character which interfer with the reponse.
Related
I'm creating Flash "memory" game, Idea to discover 2 equal cards. Here is timer which count time in how many seconds all cards are discovered. After complete game timer stops. How can I get this time from swf file and write to database? As I understand I need take this data with php file, but don't have idea how to do It.
As I know I need to do something like that:
var urlLoader:URLLoader = new URLLoader();
urlLoader.addEventListener(Event.COMPLETE, scoreSaveResponse,false,0,true);
var request:URLRequest = new URLRequest("http://mysite.com/score.php");
var urlVars:URLVariables = new URLVariables();
urlVars.time = timer.currentCount;
urlVars.userName = "yourUserName";
request.method = URLRequestMethod.POST;
urlLoader.data = urlVars;
urlLoader.load(request);
function scoreSaveResponse(e:Event):void {
//whatever you return from the php page is found in urlLoader.data
}
//LondonDrugs_MediaServices's code
But could someone explain me how to do It, because If I use this part of code nothing happens, I don't get any errors, but I don't know how to use this in php or how to write it to database.
My app will be used for Facebook, that's mean username will be used the same as in Facebook. So I think first i need to get time to PHP than get username from Facebook and write both to database.
Thank you for answers.
Try to use AMFPHP.
AMFPHP makes it possible to write a service for your application where you can store your SWF values into a PHP database.
http://www.silexlabs.org/amfphp/
I'm using facebook php sdk to get friend list of an user. But I'm strugling to get that list to flash.
The idea is that the list is always new, depending from the user loading the application. So what I need is one .html file which is loaded with php script to proccess friend list and embedded flash .swf to which php would pass information.
How can I achieve this? thanks
There are two ways to do it:
Set the flashvars to the data you want to pass to the Flash file. Since the friend list rarely changes, that should work.
Or use a URLLoader:
var loader:URLLoader = new URLLoader();
var request:URLRequest = new URLRequest("http://example.com/yourscript.php");
loader.addEventListener("complete", loader_complete);
loader.loader(request);
private function loader_complete(event:Event):void {
var scriptData:String = event.currentTarget.data;
// process data
}
Im building this AIR app on Flash CS5, and i have this TileList that loads its data (images and names) from a database.
I want to do a query with the name any item of the Tilelist when its clicked, so i need to send the name of that item to a PHP file that will execute the query.
Im thinking of a function that loads the item name to a variable when the item is clicked.
How can i send it to the PHP file and how would i load it to the query?
Many thanks to anyone that helps.
Update
The query i want on the php file goes something like this: SELECT lat, lon FROM mapdata WHERE name=theVariable;
You can send it via $_GET or $_POST to a php file. Get would look like:
... query.php?string={ INSERT ENCODED STRING }
You can use URLLoader to send and receive data to/from a web service. Simply add the data you wish (probably as URLVariables). I would avoid sending whole queries like this obviously, for security reasons.
Don't forget to clean your input before putting it in a query!
I can't help much with the PHP part - it was years since I worked in PHP. You would use $_POST or $_GET, and I suspect there are ready-made functions for cleaning up data so it's safe to send it to the database (some form of escape or encode).
As Jonatan Hedborg said:
var url:String = "http://www.[yourDomain].com/application.php";
var request:URLRequest = new URLRequest(url);
var variables:URLVariables = new URLVariables();
variables.exampleSessionId = new Date().getTime();
variables.exampleUserLabel = "guest";
request.data = variables;
var loader:URLLoader = new URLLoader();
loader.addEventListener(Event.COMPLETE, onLoadData);
loader.addEventListener(IOErrorEvent.IO_ERROR, onDataFiledToLoad);
loader.addEventListener(IOErrorEvent.NETWORK_ERROR, onDataFiledToLoad);
loader.addEventListener(IOErrorEvent.VERIFY_ERROR, onDataFiledToLoad);
loader.addEventListener(IOErrorEvent.DISK_ERROR, onDataFiledToLoad);
loader.load(request);
function onLoadData(e:Event):void {
trace("onLoadData result=" + e.target.data);
}
function onDataFiledToLoad(e:IOErrorEvent):void {
trace("onDataFiledToLoad error=" + e.text);
}
Don't forgot to add crossdomain.xml on your server, in case for example if you are making the request from another domain.
I was hoping maybe someone could provide some insight on a problem I'm having a tough time deciding how to solve.
I have a rather simple flash application users can make a quick username when connected, and the username is created inside the flash swf.
Now, I have a cron job deleting inactive usernames every ten minutes (on my mysql database where these usernames are all stored and accessed by the other people online) which is fine. But it can still get cluttered up if a bunch of people sign off at once, there is still that 10 minute window before the cron job clears them.
The users have an option to click log out in the flash application which is fine and works great. But of course many choose not to click log off they just click the browser x.
I've looked into onbeforeunload and jquery's .unload but I still need a way to get the username variable that's IN flash INTO the HTML, then use a php script to run the delete username mysql query.
Is there an easier solution?
If not, any insight on how I might pass the username variable to the html to hold onto it after the user makes their username so it can be involved with the .unload function running the php script?
EDIT::::: Maybe is there a way to create a UNIQUE string of numbers with php then pass that var to flash to include with the mysql row then since i already have that var since it was created on the html side, just along with the unload, have it delete the row that has that unique id?
If anyone things this idea would be the best approach, and if i used something like md5(uniqid(microtime()) . $_SERVER['REMOTE_ADDR'] . $_SERVER['HTTP_USER_AGENT']) to make a random iD how could i go about storing the result in a var i could place in the flash vars param then again in the jquery unload or javascript onbeforeunload if that would be better . im just more familiar with jquery
You could actually invoke an ExternalInterface command to populate a hiddenfield in your HTML coming from your SWF component.
if (ExternalInterface.available)
{
var js:String = "yourJavaScriptFunction";
var valToPass:String;
ExternalInterface.call(js(valToPass));
}
And in your HTML page, you write a javascript function:
<script language="javascript" type="text/javascript">
function yourJavaScriptFunction(valToPass)
{
document.getElementById('yourHiddenField').value = valToPass;
}
And from the unload event fired up by your page, you can access the value which was passed from your SWF.
Take note that you can call the javascript function from your SWF as soon as you get the login credentials of your user.
Hope this helps.
You want to use a combination of URLRequest, URLVariables and URLLoader to do this. See the below.
var myData:URLRequest = new URLRequest("some.php");
myData.method = URLRequestMethod.POST;
var variables:URLVariables = new URLVariables();
variables.username = 'CREATED USERNAME';
myData.data = variables;
var loader:URLLoader = new URLLoader();
loader.dataFormat = URLLoaderDataFormat.VARIABLES;
loader.addEventListener(Event.COMPLETE, dataOnLoad);
loader.load(myData);
function dataOnLoad(evt:Event){
trace('Completed');
}
This would then call the 'some.php' file with your username stored in '$_POST['username']'. Your php script can then make an impression on the db linking that username to that session (however you want to do that).
I am having some consistency problems with my flash application, when I echo out variables for flash to get, it doesn't always pick up what PHP is sending, it seems to vary from PC to PC.
I am getting info from a database, and I need to pass it to flash, say for instance I need to send through 5 variables $uid,$name,$points,$from,$page , how could I go about sending these from PHP to flash using AMFPHP?
I was told that AMFPHP would be the best tool to use for such situations, but I have NO knowledge of how it works and the sample code on the site is not making complete sense to me.
Thanx in advance!
You cannot push it from PHP to Flash - the communication has to be initiated by the Flash end. And you don't need AMFPHP for this; just use a URLLoader.
var ldr:URLLoader = new URLLoader();
ldr.addEventListener(Event.COMPLETE, onLoad);
ldr.load(new URLRequest("page.php"));
function onLoad(e:Event):void
{
var loadedText:String = URLLoader(e.target).data;
/**
* Following will throw error if the text
* is not in the format `a=something&b=something%20else`
* */
var data:URLVariables = new URLVariables(loadedText);
for(var t:Object in data)
trace(t + " : " + data[t]);
}
inside the page.php, just do a simple echo:
//don't forget to urlencode your variables.
echo "uid=$uid&name=$name&points=$points";
It seems a hassle to get involved with AMFPHP just to send a couple of variables to a flash file. I suggest you try:
Flashvars (though it's kind of limited to short variables)
LoadVariables
XML (returning the values you need as XML from PHP)
All of the above have worked consistently for me.