2 Replies Latest reply on Dec 31, 2007 2:03 AM by Greg Dove

    Send flash variables to a php file on a different domain.

    zechdc10
      I have been at this for two weeks now. I am trying to send two variables from a flash file located on newgrounds.com, kongregate.com, armorgames.com or any other site like that to a php file on my site pogolama.com.

      I have read through most of the adobe manuals for security and still have no Idea how to use those features, that's why there are so many variations of them in my code.

      I can not figure out why my php file will not get the variables I am sending it. In the following code I simplified all of my php code for testing purposes and I still cant even echo the variables that are supposed to be sent.

      I am using a virtual dedicated server on godaddy.com also I tried it on their free web hosting and their cheapest hosting plan. I have the crossdomain.xml file uploaded to pogolama.com/public_html/crossdomain.xml and have tried uploading it to pogolama.com/crossdomain.xml.

      Im not sure what else to say except, someone please help. :)

      Action Script 2.0
      varsToSend = new LoadVars();
      varsToSend.player_name = player_name;
      varsToSend.player_score = running_time;
      varsToSend.send(" http://www.pogolama.com/view.php", "POST");

      import flash.system.Security;
      import flash.system.* ;
      System.security.allowDomain("www.pogolama.com");
      System.security.allowDomain("pogolama.com");
      System.security.allowDomain("*");

      System.security.loadPolicyFile("pogolama.com/public_html/file.xml")
      System.security.loadPolicyFile(" http://www.pogolama.com/public_html/file.xml");

      PHP

      <?php
      $player_name = $_GET[player_name]; /* I have one set to GET and on to POST just to test if that is the problem. */
      $player_score = $_POST[player_score];
      echo $player_name;
      echo $player_score;
      ?>

      Crossdomain.xml
      <?xml version="1.0"?>
      <cross-domain-policy>
      <allow-access-from domain="*" />
      <allow-access-from domain="www.kongregate.com" />
      <allow-access-from domain="*.kongregate.com" />
      <allow-access-from domain="www.kongregate.com/*" />
      <allow-access-from domain="www.pogolama.com" />
      <allow-access-from domain="*.pogolama.com" />
      <allow-access-from domain="www.pogolama.com/*" />
      </cross-domain-policy>
        • 1. Re: Send flash variables to a php file on a different domain.
          Greg Dove Level 4
          Here's a bunch of notes....

          click this link in your browser.
          http://www.pogolama.com/view.php?player_name=test

          That should echo your player_name $_GET variable. It doesn't... it shows something else which means your script is not identical to your post above.

          I always put the variable names in quotes - I didn't realise that you could do it without the quotes. I just tried it locally without the quotes and it works for me.
          But you could try changing that.....
          e.g. $player_name = $_GET['player_name'];

          I had thought that you can send data without the security restrictions, it was just that you can't load the response in flash without them...the send method loads the response at the browser level - either replacing the current browser contents or in a new window or frame. So I'm not convinced that your issue is security related. But perhaps I'm wrong, others may care to comment on this.

          Anyhow....onwards.

          These don't look right.

          Try changing these
          System.security.loadPolicyFile("pogolama.com/public_html/file.xml")
          System.security.loadPolicyFile(" http://www.pogolama.com/public_html/file.xml");

          To these:
          System.security.loadPolicyFile(" http://pogolama.com/file.xml")
          System.security.loadPolicyFile(" http://www.pogolama.com/file.xml");

          And if you changed the name on the server from file.xml to crossdomain.xml then I don't think they would be necessary at all.


          The
          System.security.allowDomain("www.pogolama.com");
          System.security.allowDomain("pogolama.com");
          System.security.allowDomain("*");

          instructions are not related to data loading, but to scripting access from loaded child swfs etc. (Just from memory, I always need to check things) so are probably not necessary if you're doing data only via LoadVars.

          And....if you're sending by POST then the player_name won't arrive in the $_GET array. But you said that was a test.

          If you don't want a new browser reload or browser window opened then you should use the LoadVars sendAndLoad method and have the server return a response that you receive to another LoadVars instance inside flash.




          • 2. Re: Send flash variables to a php file on a different domain.
            Greg Dove Level 4
            Oh and one more thing... for the send command, it does need a target for the browser level. To load the response into a new browser window you would do it like this:

            varsToSend.send(" http://www.pogolama.com/view.php","_blank", "POST");