After some research, this seems to be a pretty popular issue. Unfortunately, none of the previously answered questions could solve this particular problem that I encountered.
So, firstly, setting up:
- I have a personal web server accessible externally via http, now called a web server .
- The web server is capable of serving php requests.
- I have a php script, now called php .
- php parses the POST request and uses the data submission to update the MySQL database, also located on the web server, which is hereinafter referred to as the database .
- I use the select command on a web server, connected remotely using PuTTy, to check the lines affected by php in a process that is hereinafter referred to as change checking .
- I have a Flash project created in Adobe Flash Professional CS6 using AS3, now called Flash .
- Flash creates a POST request sent to php in a process called hereinafter referred to as transmission . The transmission is correctly formatted and verified to ensure that it is correctly interpreted by php and makes the appropriate changes to the database.
- Flash is published with an Access Network Only setting. The change, however, does not seem to matter.
Now that it says Code .
Please note that I changed the URL in the code below to point to a dummy web server. I also changed the database connection information to be fictitious in this way. The rest of the structure is correct, however, including the folder structure and file name:
Flash (Code.DataTransmitter):
public function SendData():void { var myData:URLVariables = new URLVariables(); myData.update = "true"; myData.score_humans = MasterManager.gameManager.scoreHumans; myData.score_creatures = MasterManager.gameManager.scoreCreatures; var myRequest:URLRequest = new URLRequest("http://not-a-real-web-server.com/data/testgame.php"); myRequest.data = myData; myRequest.method = URLRequestMethod.POST; var loader:URLLoader = new URLLoader(); loader.dataFormat = URLLoaderDataFormat.VARIABLES; loader.addEventListener(Event.COMPLETE, OnSendDataComplete); try { loader.load(myRequest); } catch (error:Error) { trace ('Error: unable to load the document.'); } } public function OnSendDataComplete(e:Event):void { }
PHP:
<?php if (isset($_POST['update'])) { $dbhost = 'xxx.xxx.xxx.xxx'; $dbuser = 'bogususer'; $dbpass = 'boguspassword'; $mysqli = new mysqli($dbhost, $dbuser, $dbpass, 'test_game_table', 3306); if ($mysqli->connect_errno) { echo "Failed to connect to MySQL: (" . $mysqli->connect_errno . ") " . $mysqli->connect_error; } $score_humans = intval( $_POST['score_humans'] ); $score_creatures = intval( $_POST['score_creatures'] ); if ($score_humans >= 0 && $score_creatures >= 0) { // Error-check: No negative values $strquery = "update stats"; $strquery .= " set score_humans = score_humans + " . $score_humans; $strquery .= ", score_creatures = score_creatures + " . score_creatures; $strquery .= " where id = 1"; $strquery = $mysqli->real_escape_string($strquery); // Even though it should be clean, sanitize it anyways. $mysqli->query($strquery); echo "received=true"; } } echo "Hello there!"; ?>
And now, finally, the Problem .
This is a really simple problem, which probably does not deserve this preamble, but I believe that I first get all the information and eliminate its ambiguity in order to reduce the number of questions that are needed before solutions can be proposed.
- When I launch Flash in Flash Professional, the database correctly updated - checking the correctness of the changes returns the changes that are sent.
- When I launch Flash (or, more precisely, the published html wrapper) in Google Chrome on my hard drive (file: ///), the database is NOT properly updated - the change check returns that there were no changes when the changes were made .
- When I launch Flash in Google Chrome, the web server is like php (more precisely, http://not-a-real-web-server.com/flash/test_game.html ), the database is NOT updated correctly.
Put more briefly, the request only seems to work correctly when sending through Flash Professional - when sending via Google Chrome it does not work to some extent.
I would really appreciate any help in solving this problem.
Thank you in advance!