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

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. :slight_smile:

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:

<?xml version="1.0" ?>
<cross-domain-policy>
  <allow-access-from domain="*"/>
  <allow-access-from domain="mysite.com"/>
  <allow-access-from domain="www.mysite.com"/>
  <allow-access-from domain="localhost.mysite.com"/>
  <allow-access-from domain="localhost"/>
</cross-domain-policy>

php code to insert data into database:

<?
// 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();
?>
private var formFirst = ""; //First Name
private var formLast = ""; //Last Name
private var score = 99; //Overall Score, just a test value

var formText = ""; //this field is where the messages sent by PHP script will be in

var URL = "http://www.mysite.com/games/test.php"; //my login PHP url

private var textrect = Rect (10, 150, 500, 500); //just make a GUI object rectangle

function OnGUI() {
	GUI.Label( Rect (10, 10, 80, 20), "Enter First Name:" ); //Enter Name
	GUI.Label( Rect (10, 30, 80, 20), "Enter Last Name:" );

	formFirst = GUI.TextField ( Rect (90, 10, 100, 20), formFirst ); //here you will insert the new value to variable formNick
	formLast= GUI.TextField ( Rect (90, 30, 100, 20), formLast ); 

	if ( GUI.Button ( Rect (10, 60, 100, 20) , "Login" ) ){ //just a button
		Login();
	}
	GUI.TextArea( textrect, formText );
}

function Login() {
	var form = new WWWForm(); //here you create a new form connection

	form.AddField( "myform_first", formFirst );
	form.AddField( "myform_last", formLast );
	form.AddField( "myform_score", score);
	
	var w = WWW(URL, form); //here we create a var called 'w' and we sync with our URL and the form
	yield w; //we wait for the form to check the PHP file, so our game dont just hang
	if (w.error != null) {
		print(w.error); //if there is an error, tell us
	} else {
		print("Test ok");
		formText = w.text; //here we return the data our PHP told us
		w.Dispose(); //clear our form in game
	}

	formFirst = ""; //just clean our variables
	formLast = "";
}

Any insight greatly appreciated!

p.s - My hosting company is Dotster btw, if that helps (or not).

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

So will this be sufficient?

 <allow-access-from domain="to-ports"/>

Eh, that didn’t seem to work. I still get the error in the editor.

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

Okay, read it, but I’m still not sure how to proceed. How do I know what port(s) to include?

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

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.

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.

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.

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.

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.

There is nothing to fix, it’s the way it’s supposed to work. The inspector values allways take precedence over the scriptted ones.

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 :slight_smile:
so change it and it will works… (i hope)