Search Unity

crossdomain.xml policy, yes I searched, still broken.

Discussion in 'Scripting' started by silencer, Mar 11, 2011.

  1. silencer

    silencer

    Joined:
    May 16, 2009
    Posts:
    80
    I've browsed about 5 threads covering this problem and tried the little "hacks" and solutions that worked for some people, but it doesn't seem to be working for me. So I reach out to the Unity3D community. :)

    Basically I'm getting the dreaded "Rejected because no crossdomain.xml etc etc" problem. I can't insert any data into my database until it gets fixed.

    Not sure what I'm doing wrong. I tried the following things from the solutions found on the forum:

    1) Save XML at UTF-8.
    2) Upload to root
    3) Upload to game directory
    4) In the editor, I changed the editor setting for Security Emulation to my website's domain.
    5) Downloaded Firebug, and found that it actually does look for crossdomain.xml, seemingly in the right place, but times out...

    Can't get this error to go away in the editor or in my actual build.

    Here's the simple code I'm using below:

    crossdomain.xml:
    Code (csharp):
    1. <?xml version="1.0" ?>
    2. <cross-domain-policy>
    3.   <allow-access-from domain="*"/>
    4.   <allow-access-from domain="mysite.com"/>
    5.   <allow-access-from domain="www.mysite.com"/>
    6.   <allow-access-from domain="localhost.mysite.com"/>
    7.   <allow-access-from domain="localhost"/>
    8. </cross-domain-policy>
    9.  
    php code to insert data into database:
    PHP:
    <?
    // CONNECTIONS =========================================================
    $host "myhost"//put your host here
    $user "myuser"//in general is root
    $password "mypassword"//use your password here
    $dbname "mydb"//your database
    mysql_connect($host$user$password) or die("Cant connect into database");
    mysql_select_db($dbname)or die("Cant connect into database");
    // =============================================================================
    $first $_POST["myform_first"];
    $last $_POST["myform_last"];
    $score $_POST["myform_score"];

    if(!
    $first || !$last
        {
            echo 
    "Login cant be empty.";
        } 
    else 
        {
          
    mysql_query("INSERT INTO Persons (FirstName, LastName, Score)
          VALUES
          ('
    $first','$last','$score')");

          echo 
    "1 record added";
        }
    // Close mySQL Connection
    mysql_close();
    ?>
    Code (csharp):
    1. private var formFirst = ""; //First Name
    2. private var formLast = ""; //Last Name
    3. private var score = 99; //Overall Score, just a test value
    4.  
    5. var formText = ""; //this field is where the messages sent by PHP script will be in
    6.  
    7. var URL = "http://www.mysite.com/games/test.php"; //my login PHP url
    8.  
    9. private var textrect = Rect (10, 150, 500, 500); //just make a GUI object rectangle
    10.  
    11. function OnGUI() {
    12.     GUI.Label( Rect (10, 10, 80, 20), "Enter First Name:" ); //Enter Name
    13.     GUI.Label( Rect (10, 30, 80, 20), "Enter Last Name:" );
    14.  
    15.     formFirst = GUI.TextField ( Rect (90, 10, 100, 20), formFirst ); //here you will insert the new value to variable formNick
    16.     formLast= GUI.TextField ( Rect (90, 30, 100, 20), formLast );
    17.  
    18.     if ( GUI.Button ( Rect (10, 60, 100, 20) , "Login" ) ){ //just a button
    19.         Login();
    20.     }
    21.     GUI.TextArea( textrect, formText );
    22. }
    23.  
    24. function Login() {
    25.     var form = new WWWForm(); //here you create a new form connection
    26.  
    27.     form.AddField( "myform_first", formFirst );
    28.     form.AddField( "myform_last", formLast );
    29.     form.AddField( "myform_score", score);
    30.    
    31.     var w = WWW(URL, form); //here we create a var called 'w' and we sync with our URL and the form
    32.     yield w; //we wait for the form to check the PHP file, so our game dont just hang
    33.     if (w.error != null) {
    34.         print(w.error); //if there is an error, tell us
    35.     } else {
    36.         print("Test ok");
    37.         formText = w.text; //here we return the data our PHP told us
    38.         w.Dispose(); //clear our form in game
    39.     }
    40.  
    41.     formFirst = ""; //just clean our variables
    42.     formLast = "";
    43. }
    44.  
    Any insight greatly appreciated!

    p.s - My hosting company is Dotster btw, if that helps (or not).
     
    Last edited: Mar 11, 2011
  2. Dreamora

    Dreamora

    Joined:
    Apr 5, 2008
    Posts:
    26,601
    Given the crossdomain.xml is at mysite.com:80/crossdomain.xml (thats where it must be not in some subfolder) the only thing remaining is the missing to-ports entry in your crossdomain file.

    also all the port entries after the wild card one are pretty much useless but I guess you added wildcard just for the purpose of testing if its working at all / related to the urls
     
  3. silencer

    silencer

    Joined:
    May 16, 2009
    Posts:
    80
    So will this be sufficient?

    Code (csharp):
    1.  <allow-access-from domain="to-ports"/>
     
  4. silencer

    silencer

    Joined:
    May 16, 2009
    Posts:
    80
    Eh, that didn't seem to work. I still get the error in the editor.
     
  5. Dreamora

    Dreamora

    Joined:
    Apr 5, 2008
    Posts:
    26,601
    to-ports is an own key, not a domain. please check the security sandbox documentation for more information on how crossdomain.xml etc work or look up on it on the web as its the same mechanism used in flash and silverlight too
     
  6. silencer

    silencer

    Joined:
    May 16, 2009
    Posts:
    80
    Okay, read it, but I'm still not sure how to proceed. How do I know what port(s) to include?
     
  7. Dreamora

    Dreamora

    Joined:
    Apr 5, 2008
    Posts:
    26,601
    if you don't know you can always specify * to make it "all" basically.
    if you use WWW with http:// and without an explicit port its normaly port 80
     
  8. silencer

    silencer

    Joined:
    May 16, 2009
    Posts:
    80
    Okay, I found out what the problem is.

    Using firebug, the game tries to look for the crossdomain.xml at the following URL:

    http://www.mysite/crossdomain.xml

    It seems as if the ".com" part is completely missing. The only thing is, I'm not sure where the bad URL exist. I've checked my build settings, my scripts, and I can't find a malformed URL. This is maddening.
     
  9. silencer

    silencer

    Joined:
    May 16, 2009
    Posts:
    80
    nvm.

    Updating a Script file, or reimporting the script doesn't actually update the attached component in the game world, at least for Public data (maybe private too?).

    You have to detach the object, then reattach it, THEN whatever has changed will show up in the game.

    Please fix this at some point guys.
     
  10. Antitheory

    Antitheory

    Joined:
    Nov 14, 2010
    Posts:
    549
    No updating the default value for a Public property in your script does not change the value on the component you have already attached to an object. I am constantly making this mistake too... although I don't think it's incorrect for Unity to do this. It would be MUCH MORE annoying if Unity were to reset all the properties to their default values every time you made a change to the script. Unity doesn't realize you only changed the default value of property when you save/reimport a script.
     
  11. silencer

    silencer

    Joined:
    May 16, 2009
    Posts:
    80
    True, but I feel if the value updated for the specific data (on the fly update), it would be more user friendly.

    As it is, I am fine simply reimporting, or reattaching, I guess.
     
  12. Antitheory

    Antitheory

    Joined:
    Nov 14, 2010
    Posts:
    549
    You wouldn't ever need to reimport as this happens automatically when you save the file. Reattach and you will lose all the values you set in the inspector. Really though if you want to experiment with values you should just do this in the inspector and not in the script itself. Or if you have the script running in many different places and you want to change these values all at the same time, then simply set the variable to Private and it will update it everywhere.
     
  13. appels

    appels

    Joined:
    Jun 25, 2010
    Posts:
    2,687
    There is nothing to fix, it's the way it's supposed to work. The inspector values allways take precedence over the scriptted ones.
     
  14. cypress-art

    cypress-art

    Joined:
    May 5, 2011
    Posts:
    2
    i use the same script.. and the solution found you in the inspector.

    i change URL in the script, but when you add the script to a gameobject (maincamera) you see in the inspector allways the "old" URL without the .com :)
    so change it and it will works.. (i hope)