Server Side Highscores

Author: (Kevin Lindeman)

Description
This set of scripts will send a player's name and score to a server to be stored in a MySQL Database, and then also loaded by the game to be seen.

Step 1: Create the blank MySQL Database
Go into whatever you use to manually modify a MySQL Database (I usually use phpMyAdmin), and create a new database.



Now go into that database and click the SQL tab to run your own SQL



And paste this SQL Query into the box and hit Go. Note: If you get an SQL Syntax error, replace TYPE=MyISAM; by ENGINE=MyISAM; as TYPE is deprecated.

Step 2: Edit the server side scripts
Edit these scripts to reflect your MySQL host server, user, password, database. The table name "scores" should not be edited unless you edited the SQL Query in Step 1.

PHP - addscore.php
This script will take the name and score HSController.js passes to it and adds them to the MySQL Database.

addscore.php using PDO
This is the same code/file above, but using better practices in PHP.

''Please! This code need to be tested.'' ''Tested, confirmed not working. Use snippet above.''

PHP - display.php
This script will take the top 5 scores from the MySQL Database and put them in a GUIText.

Upload them to wherever you want them on your server.

display.php using PDO
This is the same code/file above, but using PDO.

XML - crossdomain.xml
Unity requires that websites you want to access via a WWW Request have a cross domain policy. Upload this file to the root of your web server.

Step 3: The Unity HSController Script
You will attach this script to a GameObject. You need to be able to supply it with a string containing the players name, and a string containing the players score. You also need to edit the URLs in it that point to the correct addscore.php script and the display.php. You will also need to supply it with a GUIText if you want it to get the scores (otherwise you can ignore the getScores function).

You will also need to include the MD5 script previously posted to this Wiki in your project folder.