dcsimg
A Flash Developer Resource Site

Page 1 of 2 12 LastLast
Results 1 to 20 of 22

Thread: Run PHP script without opening a browser

  1. #1
    Banned
    Join Date
    Dec 2003
    Location
    Denmark, Europe
    Posts
    53

    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?

  2. #2
    Senior Member
    Join Date
    Aug 2002
    Location
    Dublin, Ireland
    Posts
    1,749
    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();

  3. #3
    Banned
    Join Date
    Dec 2003
    Location
    Denmark, Europe
    Posts
    53
    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"?

  4. #4
    Senior Member
    Join Date
    Aug 2002
    Location
    Dublin, Ireland
    Posts
    1,749
    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();
    }
    }

  5. #5
    Senior Member
    Join Date
    Aug 2002
    Location
    Dublin, Ireland
    Posts
    1,749
    Sorry, that should be ".sendAndLoad"

  6. #6
    Banned
    Join Date
    Dec 2003
    Location
    Denmark, Europe
    Posts
    53
    I dont really see where you save the variables??
    Do you save them on local comp only or what?

  7. #7
    Senior Member
    Join Date
    Aug 2002
    Location
    Dublin, Ireland
    Posts
    1,749
    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.

  8. #8
    Banned
    Join Date
    Dec 2003
    Location
    Denmark, Europe
    Posts
    53
    nono, global store please WHat should I write exaclty to make the php file "run" its scripts without making it visible?

  9. #9
    Senior Member
    Join Date
    Aug 2002
    Location
    Dublin, Ireland
    Posts
    1,749
    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.

  10. #10
    Banned
    Join Date
    Dec 2003
    Location
    Denmark, Europe
    Posts
    53
    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?

  11. #11
    Senior Member
    Join Date
    Aug 2002
    Location
    Dublin, Ireland
    Posts
    1,749
    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.

  12. #12
    Banned
    Join Date
    Dec 2003
    Location
    Denmark, Europe
    Posts
    53
    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?

  13. #13
    Senior Member
    Join Date
    Aug 2002
    Location
    Dublin, Ireland
    Posts
    1,749
    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();
    }
    }

  14. #14
    Banned
    Join Date
    Dec 2003
    Location
    Denmark, Europe
    Posts
    53
    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.

  15. #15
    Senior Member
    Join Date
    Aug 2002
    Location
    Dublin, Ireland
    Posts
    1,749
    Can you give me a URL and upload your FLA?

  16. #16
    Banned
    Join Date
    Dec 2003
    Location
    Denmark, Europe
    Posts
    53
    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.

  17. #17
    Banned
    Join Date
    Dec 2003
    Location
    Denmark, Europe
    Posts
    53
    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.

  18. #18
    Senior Member
    Join Date
    Aug 2002
    Location
    Dublin, Ireland
    Posts
    1,749
    I missed out the return object for SendAndLoad, should have been:
    x.sendAndLoad("score.php",x)

    Anyway, this works for me.

  19. #19
    Senior Member
    Join Date
    Aug 2002
    Location
    Dublin, Ireland
    Posts
    1,749
    I can't open your FLA, but you should be able to use what I just uploaded.

  20. #20
    Banned
    Join Date
    Dec 2003
    Location
    Denmark, Europe
    Posts
    53
    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
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center