-
Run PHP script without opening a browser
I have a program that sends some variables to a php file like this:
file.php?var1=something&var2=somethingelse
Then the php file opens up in an external browser and saves the variables down to a txt file.
The swf file switches to another swf file.
My problem is that it looks like **** when a browser opens with nothing in it. Another problem is that the variables are kinda secret (Its a highscore) so i would like to run the php-script without letting the user see any browser window open.
DOes anyone have a suggestion what I could do?
-
It sounds like you are using GetURL.
Better to load the variables directly into the movie eg by using LoadVars.load(), LoadVars.sendAndLoad()
Better still to do it as XML and use XML.load() or XML.sendAndLoad();
-
Sounds like you explain me how to load the variables but I DO know how to load them. I load them from a txt file. I use php to save new variables in the txt file. And how do I do that "silent"?
-
The same way.
If you think about it, saving a high-score is just the same as a request for data, especially if you want the page to confirm back to the flash file that the save was successful.
1. SWF sends data for high-score
var x = new LoadVars();
x.score = 956;
x.player = "Cedric The Greater Than The Lesser Cedric";
x.load(store_highscore_url);
x.onLoad = function (success) {
if (success) {
trace("Highscore saved" );
doTheNextThing();
}
}
-
Sorry, that should be ".sendAndLoad"
-
I dont really see where you save the variables??
Do you save them on local comp only or what?
-
Flash can't save other than the SharedObject (a bit like a cookie). The PHP receives the variables and does stuff with them, for example, it might write the scores to a database.
If you want the game to run locally and store scores locally, you can use a third-party product such as SWFStudio or *********** to package your SWF as an EXE which can write the files.
-
nono, global store please WHat should I write exaclty to make the php file "run" its scripts without making it visible?
-
I'm afraid I don't know much PHP. If it was ASP it would be easy enough:
code:
<%
dim score, player, filesys
score = request("score")
player = request("player")
Set filesys = CreateObject("Scripting.FileSystemObject")
Set filetxt = filesys.OpenTextFile("c:\highscore.txt", ForAppending)
filetxt.WriteLine(player+":"+cstr(score))
%>result=High-score logged for player<%=player%>
Have a look at some of the online stuff for PHP eg:
PHP Syntax
I imagine there is a script online somewhere that you can download that does more or less exactly what you need.
-
But well at this moment it all works fine except the php-browser doesnt close after it has loaded and save vars in the txt file. I looks lame with a new windows open. Maybe a script to close the window would allow a fast blink from a browser and the close it again?
-
If you have a PHP that does what you want, then you simply sendAndLoad to it and there will be no open window to close.
Check that your FLA doesn't do a GetURL.
-
Well ok. If the php file is named score.php how would I make the swf file run the php file exactly how you say?
-
Originally posted by AlsoGaiusCoffey
The same way.
If you think about it, saving a high-score is just the same as a request for data, especially if you want the page to confirm back to the flash file that the save was successful.
1. SWF sends data for high-score
var x = new LoadVars();
x.score = 956;
x.player = "Cedric The Greater Than The Lesser Cedric";
x.sendAndLoad("score.php");
x.onLoad = function (success) {
if (success) {
trace("Highscore saved" );
doTheNextThing();
}
}
-
on (release) {
var x = new LoadVars();
x.numberone = 956;
x.numbertwo = "Cedric The Greater Than The Lesser Cedric";
x.sendAndLoad("load.php");
}
Shouldnt this be enough?
It should it then open load.php and use $numberone as 956 and $numertwo as "Cedric The Greater Than The Lesser Cedric";??
Is yes something is wrong. I tried it but it doesnt work.
-
Can you give me a URL and upload your FLA?
-
http://80.62.125.212/loadtest/load.p...ertwo=hopeucan
Try to change the variables as you write this adress. Then you see the php works properly.
-
http://80.62.125.212/loadtest/
Thisisit.fla is the file I use. The code is in the button.
load.php is the php file i write to.
-
I missed out the return object for SendAndLoad, should have been:
x.sendAndLoad("score.php",x)
Anyway, this works for me.
Last edited by AlsoGaiusCoffey; 07-11-2008 at 07:31 AM.
-
I can't open your FLA, but you should be able to use what I just uploaded.
-
http://80.62.125.212/da/menu.html
Ok. here you can see the result of your help Thankyou very much for using half an hour on a stranger
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|