Setting up a leaderboard using PHP and a database
Games are more fun when there is a leaderboard of high scores that the players have achieved. Even single-player games can communicate with a shared web-based leaderboard. This recipe creates the web server-side (PHP) scripts to set and get player scores from a SQL database. The recipe after this one then sees us creating a Unity game client that can communicate with this web leaderboard’s server.
Getting ready
This recipe assumes that you either have your own web hosting or are running a local web server. You could use the built-in PHP web server or a web server, such as Apache or Nginx. For the database, you could use a SQL database server such as MySQL or MariaDB. However, we’ve tried to keep things simple using SQLite – a file-based database system. So all you actually need on your computer is PHP 8, since it has a built-in web server and can talk to SQLite databases, which is the setup on which this...