This is a simple set up for score REST API for your PHP5 + MySQL server. System handles multiple applications, and multiple tops for same application. It doesn't have an admin panel, so hope you don't mind creating new apps and tops directly from database managment (like PhpMyAdmin)

Contents

Download

Installation

Import db.sql file into your database

Place all files in one folder

in mysql.php change

  • $this->host = "localhost";
  • $this->db = "dbname";
  • $this->user = "root";
  • $this->pass = "password";

to match your connection settings

in score.php change $passcode = "dAS7M2qXT"; to your own pass, so no one else would be able to use API without knowing the passcode

Save score result

Example request of saving score results:

http://yoururl/score.php?action=insert&pass=dAS7M2qXT&app=testapp&game=level1points&username=ar2rsawseen&score=100000

Parameters:

  • action - what to do, in this case "insert" new score
  • app - code name for your app stored in db (if provided app codname doesn't exist, script will create one)
  • game - identification of top, since one game can have multiple tops, for example different top for each level, or each platform, etc(if provided top does not exist, script will create one)
  • username - identification who submitted score
  • score - score to submit, data type - double
  • comment (optional) - some optional comment, default value NULL
  • time (optional) - timestamp, when score was achieved, default value current timestamp
  • type (optional) - return type json or xml, default - xml

Note that right now only best score for each username is saved, but it can be modified to save for example top 10 of each players scores, or all player's submitted scores.

This request returns players current position in top:

XML example:

	
	1
	

JSON example:

	{"place":1}
	

Get top data

Example request of getting top users for specified app's specified top:

http://yoururl/score.php?action=top&pass=dAS7M2qXT&app=testapp&game=level1points

Parameters:

  • action - what to do, in this case display "top"
  • app - code name for your app stored in db
  • game - identification of top
  • limit (optional) - limit of rows to return, default value 10
  • start (optional) - from which row to start select (for pagination), default value - 0
  • type (optional) - return type, json or xml, default - xml

Example information returned by this request:

XML:




ar2rsawseen


100000
1


ar2rsawseen2


99999
2


JSON:

[{"username":"ar2rsawseen","comment":"","time":"1323691323","score":"100000","place":1},
{"username":"ar2rsawseen2","comment":"","time":"1323697032","score":"99999","place":2}]

If no results found:

XML:


no result

JSON:

{"error":"no result"}

Latest changes

None for now