A simple and open source Leaderboard system written in PHP.
IMPORTANT: PSL is insecure. It can be manipulated by spying the network traffic or by decompiling your application. This is only for demonstration. Use at your own risk.
-Add name and score by a simple web request
-Get every registered name + score
-Webserver (with PHP support)
-MySQL Database
Of course! With the second part of the following tutorial you can set up your own free and simple leaderboard system in 5 minutes!
Simple Explanation
Download the five scripts which are listed down below. Then you have to change in four scripts the login data for your database and in 2 scripts you have to choose a password for the administration panel. After that, uploud the scripts to your webserver. Open in your webbrowser http://yourserver.com/setup.php. When completed, it created a table in the database for the leaderboard. Now you can add a new score with http://yourserver.com/addScore.php?name=username&score=100 and get a list of all scores with http://yourserver.com/getScore.php. Below are some code samples for Unity/C#.
Explanation for beginners
Firstly, download the five scripts which are listed down below, you need it later.
In our example we will use https://www.000webhost.com/. They offer us a webserver and a MySQL server. Firsty you have to create an account.
Enter a name and a password for your site and write it down so you don't forget it!
In the next step it will tell you to choose a method. You have to choose "Uploud Your Existing Website".
After that it will open a new tab. It should look like in the picture below. Don't close it.
Go back to your first browser tab and click on "Manage Website", which appears when you hover the mouse over it.
On the left panel you have to click on "Tools"
After that click on "Database Manager"
Now you should see the following panel. Click on "New Database"
Enter a name for your database, a username and a password and click on "Create". Don't forget to write the database name down.
Now you have to drag the five scripts and drop it into the second tab to uploud the scripts to your webserver.
Then you have to select each script individually and click on "edit".
You have to change in each script something:
setup.php, addScore.php, getScore.php, administrationpanel.php:
$servername should be "localhost"
$username should be the username of the database
$password should be the password of the database
$dbname should be the name of the database
administrationpanel.php, login.php:
$password should be a password which you need to enter the administrationpanel
Don't worry, nobody can see your password in the files.
The scripts which are listed down have to be moved onto your webserver.
using UnityEngine;
using System.Net;
public class PSL : MonoBehaviour
{
string url = "https://mywebsite.com";
public void addScores(string username, int score)
{
WebClient wc = new WebClient();
wc.DownloadString(url + "/addScore.php?name=" + username + "&score=" + score);
}
public void getScores()
{
WebClient wc = new WebClient();
Debug.Log(wc.DownloadString(url + "/getScore.php").Replace("<br>", "\n"));
}
}
This project is completely non commercial and also open source. Feel free to develop new functions.
PSL is not 100% secure. It can be manipulated by spying the network traffic or by decompiling your application. Use at your own risk.
Readme V1.0
MIT License
Copyright (c) 2019 louis-e
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.