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:
- Save XML at UTF-8.
- Upload to root
- Upload to game directory
- In the editor, I changed the editor setting for Security Emulation to my website’s domain.
- 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).