Creating your own Leaderboard / Highscores Easy and Free (PHP & MySQL) [UPDATED 2020]

  • 41 favourites


Attached Files

The following files have been attached to this tutorial:



Download now 180.37 KB


23,333 visits, 62,659 views


PHP to Read and Write Scores

Go to your Dashboard and access your File Manager. Here you can upload files, images, sounds, games, etc... This is where the PHP files will be saved (the ones you downloaded attached to this tutorial).

You should click "public_html" directory and upload there your files and folders. To Upload your PHP files, click the "Upload" button and select 'savescores.php' and 'getscores.php' and 'login.php'. You can also upload a zip file and extract it once uploaded.

Edit Your Database Connection Info

Edit the PHP file 'login.php' and update the database part according to the data of your account - like the image shown below. Then save the changes.

(You can also find this data on your Dashboard Tools -> Database Manager)

Reading Scores (testing our PHP)

To read your highscores, we use the file 'getscores.php'.

Type on your internet browser (Google Chrome, Firefox, etc) your free domain + the path to 'getscores.php'.

For example, my URL to read scores is:

If you can see the 'best scores' you previously saved on the database, you have set it up correctly. Congratulations! :)

Writing Scores

You save scores calling the 'savescores.php' file in your website. For example, to save 'John' and '51' points, we will call from Construct 2 the following URL:

Save a new score using the 'savescores.php'.

Then try 'getscores.php' again. If you can see the new score you just saved on the database, you have everything ready!

The server part is ready. Now you only need to set up Construct 2!


  • Order by
Want to leave a comment? Login or Register an account!
  • Great tutorial for a refresher. Ive just finished reading through the tutorial and will soon be implementing the PHP.

  • [FIXED] The scripts save/get should be updated according to the latest PHP formatting rules. After fiddling after a bit I found that in the save.php you should remove the "id" parts when inserting the score.

  • Bro... You're GOD for me right now, thank you so much!

  • Thank you so much for posting this! I got this to work with construct 3 and now im integrating the code with my custom name writing and text graphics. (Any thing system font is ugly on any device).

    Also a great way to learn interaction with construct 3 and a server.

    • Great! Yes, it should work in C3 as well.

      If you liked my tutorial, give it some love! A thumbs up or Favorite, so it can help others too ;)

  • Is there anyway for me to change the code so that is will give you the lowest scores as my game doesn't have a score but rather a speed run clock that goes up the longer you take to finish. So my "high scores" need to be the ones with the lowest values can you help me at all with where and what in the code I need to change?

    • Yes!

      Open 'getscores.php' and replace "ORDER BY score DESC" (scores are ordered DESCending - higher first then lower) with "ORDER BY score ASC" (scores will be ordered ASCending - lowest values first, then higher)

      // Retrieve data from database

      $sql = "SELECT *

      FROM scores

      ORDER BY score DESC // Replace 'DESC' with 'ASC'

      LIMIT 10"; // The 'LIMIT 10' part will only read 10 scores. Feel free to change this value

  • Load more comments (35 replies)