How do I export my php/mysq based game with xdk (crosswalk)

0 favourites
  • 5 posts
From the Asset Store
Advanced inventory mechanics for your RPG game (Array-based). Take Items, split them, pick up them, read the description
  • I have tried building my php/mysql based html5 game with intel's xdk (building with crosswalk) and though the game connects and sends and posts data from the db online when uploaded, it doesn't seem to work after building the app with xdk. I've built a few game in construct and successfully exported them and are in the play store and work without a hitch. I feel like I'm missing something and not sure what. Maybe I'm missing a plugin check box. What should I have checked to make sure that the app can talk to the data base. I have my domain listed in the domain list or whitelist as well. Any ideas? I'm not sure what plugins to include. The app uses nothing like camera or vibration. I have the browser and ajax objects in my c2 made game. It works great as a web app.

  • For security reasons AJAX calls should be done within one domain - that's why you can't connect to your PHP/MySQL from your app. There are several work-arounds. One of them is to create a .htaccess file in the directory where you have your index.php with the following content:

    <IfModule mod_headers.c>
    Header set Access-Control-Allow-Origin "*"
    </IfModule> [/code:3boz2zyb]
  • Ok I put the code above into the .htaccess file on my domain. I also put:

    header('Access-Control-Allow-Origin: *');[/code:312q5gjm]
    in my .php files 
    I'm uploading my .php files and my .capx file if anyone would care to take a look.
    I replaced the the mysql db username and password in all the php files but i assure you they are set correctly in the originals. i just changed them here for obvious purposes. 
    I zipped all the files and uploaded them to my own space. 
    I obviously still can't get anything to work. The login doesn't work after I build it in xdk. I'm building with crosswalk and exporting via cordova. Once I get the .apk and test it, I can't login. It works fine when uploaded as html 5 to my website.
  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • azrail13 - have you tried just displaying the the AJAX.lastdata in a text object to see what your getting back. After looking at your login.php I can see a few errors that might come up. You say this worked when it was in testing but I can't see how. you might be getting a SQL error and not even know it becuase you are storing the result in an (int) variable so the string is just getting converted to a 0 (int zero)

    Maybe SQL has gotten better at adapting to syntax usage but his looks like it shouldn't work?

    $qz = "SELECT id FROM members where username='" . $username . "' and password='" . $password . "'";
    $qz = str_replace("\'", "", $qz);
    $result = mysqli_query($con, $qz);
    You are stripping single quotes from the query string before executing it but that means you are comparing columns (username & password) to non string values which SQL will interpret as other columns and throw an error because they don't exist
    "WHERE username=player1 &password=test" will throw an error becuase SQL will think the values "player1" and "test" are columns  since they are not in single quotes
    It should be "WHERE username='player1' &password='test'" (The single quotes allow SQL to know you compairing the column value to a string value and not another column or equation
    And while this might work it is extremely unstable way of getting the data. On the off chance more than row is returned this will break and what if the username and password don't find a match? 
    while ($row = mysqli_fetch_array($result)) {
        echo $row['id'];
    Try using this
    //make sure param is there and catch it if not so PHP doesn't throw a Notice error
    $username = isset($_GET['fname']) ? $_GET['fname'] : '';
    $password = isset($_GET['fpass']) ? $_GET['fpass'] : '';
    //Validate you received the params you expected
    if($username=='' || $password==''){
        echo 'Invalid login';
        exit; //make sure no other code is executed beyond this error;
    //protect from SQL injection
    $username =  mysqli_real_escape_string($con,$username); 
    $password =  mysqli_real_escape_string($con,$password);
    //You need the single quotes around the values or SQL will break
    $qz = "SELECT id FROM members where username='" . $username . "' and password='" . $password . "'";
    $result = mysqli_query($con, $qz);
    //There should only be 1 row returned. No need for a while statement
    $row = mysqli_fetch_array($result);
    //The $row may be null if it was invalid username and password combo
        echo 'Invalid login';
        exit; //make sure no other code is executed beyond this error;
    echo $row['id']
    Lastly keep in mind that $row['id'] will be returned as a string (all echo statements doesnt matter what they are are returned in string type as literal text) 
    so first in C2 you need to compare against the possible error and catch it
    Condition (AJAX.LastData=='')  - Ajax was empty and something went wrong. stop code
    Condition (AJAX.LastData=='Invalid login') - Ajax returned a notice of invalid login and you need notify the user so they can try again 
    Then if that passes you need to store it in userid but convert the (string) you received from php to (int) so it is casted correctly to the userid variable
    Action userid = int(AJAX.LastData)
  • Ahh I knew I was screwing something up in there. I haven't messed with php/mysql coding for years. A lot has changed and I've been corrected on a few occasions for using depreciated code. I actually had that set up differently before and my return worked out fine. everything worked as planned, I may have sent an edited file that no longer works. As I've added code after realizing things where not working when I built the .apk

    I will go through with a fine tooth comb and straighten it all out.

    I'm thinking it's a much better deal to get my highscore functions from google play instead of using my own db and code in the end.

    Edit: I forgot to thank you both for going through my mess of code. So thank you so much. I really do appreciate the help. I always wish I could do something for people that take the time out of their day to help another. So if there is anything I can do...

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)