This is a basic tutoarial using the following:
This is mainly an ActionScript tutorial, the PHP and MySQL part is minimized to "copy and paste"
Stages
1)Getting a server
2)Setting the files and writing them
3)Setting the actionscript
WARNING: This scoreboard tutorial will produce a working but hackable scoreboard, you'll need to protect it better if you want it practically used , I might write a follow up tutorial or I might get Denvish to :P
Getting a server
The first thing you need to do is get a server that supports both PHP and MySQL there are plenty of free servers providing these services and you shouldn't care about ADs since you aren't using the pages themselves (you're loading them directly to flash), if you want to get something professional you should get a payed server, 3qhost are fair and trustworthy (I used them twice) and apthosting are pretty good too.
Setting the script
This script will include 1 php file and 1 sql table, let's start with the tricky sql part, your host should have some form of SQL access (preferable CPanel with PhpMyAdmin which is best to use). connect to your SQL (as provided) and create a new scores table:
CREATE TABLE `scores` ( `name` VARCHAR( 30 ) NOT NULL , `score` INT NOT NULL , `id` INT NOT NULL AUTO_INCREMENT , PRIMARY KEY ( `id` ) );
basically I created a table with a place for names and a place for scores, names are limited to 30 chars but you can use more if you'd like
now make sure you have the sql connection script ready, it's
mysql_connect(<server>,<username><userpass
>);
select_db(<database name>);
create a new php file, name it highscores.php or something similar, and put the following script in it, costumizable parts have <>'s
<?
$action=$_POST['action'];
echo "returned=1";
echo $_POST['lolk'];
function spitScores($n){
$result=mysql_query("SELECT * FROM `scores` WHERE 1 ORDER BY `score` DESC");
for($i=0;$i<10;$i++){
$row = mysql_fetch_array($result, MYSQL_BOTH);
echo "&row" . $i . "=" . $row['name'] . "&score" . $i . "=" . $row['score'];
}
}
function insertScore($name,$value){
if($value<100000){
mysql_query("INSERT INTO `scores` ( `name` , `score` , `id` ) VALUES ('$name', '$value', '');");
}
}
function clearDB(){
mysql_query("DELETE * FROM 'scores'");
}
if($action!=null){
mysql_connect(<server>,<username><userpass
>);
mysql_select_db(<database name>);
}else{
die ("I cannot find the action");
}
if($action=="view"){
spitScores(10);
}else if($action=="insert"){
$name=$_POST['name'];
$score=$_POST['score'];
$domain=$_POST['domain'];
//if(($domain=="http://www.gamesofgondor.c
om") || ($domain=="http://uploads.ungrounded.net")
){
insertScore($name,$score);
// }else{
// echo "Stop trying to cheat the system";
// }
}else if($action=="clear"){
$pass=$_POST['password'];
if($pass=="<myclearpasshere(give it to noone)>"){
clearDB();
}
}else{
"Please don't hack this, if scoring high REALLY means that much to you just email us and we'll give you a highscore, just don't be such a godamn lamer and ruin someone's hard work" ;
}
?>
once you have this code you're pretty much set, all you have to do is fetch the scores from flash...
you'll notice you have a domain check with a remark bound before it at a point, you can unremark it and alter it as you need
The Actionscript
You have 3 actions in this scoreboard script, view insert and clear, you only need to mess with view and insert, for example to insert a score you can do
action="insert";
name="Inglor"
score=2000;
loadVariablesNum("www.site.suffix/path/hig
hscores.php",1,"POST");
to view the scores you need to do
action="view";
loadVariablesNum("www.site.suffix/path/hig
hscores.php",1,"POST");
Again, this script is not secure, only use it for education and learning how highscores work, the view action loads the variables into _level1, toy with it to check the format, it loads 10 scores (configurable)
enjoy!