Saving data to file (HiScore table)

AutmnLeaf

New member
Tutorial Author
Joined
Feb 19, 2018
Messages
31
Hello everyone!

This question was answered in the Monkey-X forum, I checked the archive, but the answer wasn't in the archive. This may be helpful to many people.

How to implement hiscore system in HTML5 target without the native filesystem.

My best guess is to use POST and GET methods and use PHP.

I would like to have implementation where the hiscores are printed into webpage, not inside the game itself. Should be simple, but I know hardly anything about PHP.
 

magic

Active member
3rd Party Module Dev
3rd Party Tool Dev
Joined
Mar 5, 2018
Messages
234
This is my solution in general. basicaly you need 3 task.
1. First task is to send the score to the php using httprequest
- use http:/yoursite.com/bla.php?name=somename&score=1234 as address. This is how you send input to php file.
- in php you do:
$name=$_GET["name"];
$score=$_GET["score"];
This is how you get the value send by your app.​
- You app send this score data only when user make a big score progress​
2. Process the value into SQL database
-You connect with database using mysqli_connect("localhost",$user,$password,$name);
-You put this data $NAME, $SCORE and TIMESTAMP into database
-You let the TIMESTAMP auto. Means it will auto put current server time when the score is send.
-You use command $quary = "INSERT INTO yourUserData (NAME,SCORE) VALUE({$NAME},'{$SCORE}')";
-This php just put data in SQL, data will be filter and delete during display below​
3. To display all users score in website
-Create another php to display result.
-Read the SQL data by assending order of the score.
$quary = "SELECT * FROM yourUserData ORDER BY SCORE ASC";​
-You can limit the amount to display by look at TIMESTAMP or minimum SCORE
-You can also delete SQL data which it TIMESTAMP or minimum SCORE not meet the minimum. For example score too low or data has been long time ago.
-You delete using $quary = "DELETE FROM yourUserData WHERE SCORE>= 40000";​

Hope this can help.
 

AutmnLeaf

New member
Tutorial Author
Joined
Feb 19, 2018
Messages
31
Very good answer to the topic! I try to implement this, when I have the time to it. I'm sure many people will find this useful.
 

Taiphoz

New member
Joined
Jun 21, 2017
Messages
19
Happened to stumble on this thread while at the same time be flipping through some of my old website work and thought this might help, its the old(Read super old) php code I did for one of my first online score tables, I doubt much in the way of php has changed since then so it probably still works just replace the database info with what ever your using.

Code:
<?php
//
// Add Score URL
//
//    http://www.teamrebellion.com/Score/add.php?gamename=Terminal_Invaders&gamepass=trscore&playername=Yavin&playerscore=99&playerlevl=10&difficulty=Easy
//
//

//$gamepass=$_GET['gamepass'];
//$gamename=$_GET['gamename'];
//$playername=$_GET['playername'];
//$playerscore=$_GET['playerscore'];
//$playerlevel=$_GET['playerlevel'];
//$difficulty=$_GET['difficulty'];

    $secret_string = "connor";

    $gamename = $_GET['gamename'];
    $gamepass = $_GET['gamepass'];
    $playername = $_GET['playername'];
    $playerscore = $_GET['playerscore'];
    $playerlevel = $_GET['playerlevel'];
    $difficulty = $_GET['difficulty'];
    $md5 = $_GET['md5'];


    $md5hash = md5($secret_string . $gamename . $gamepass . $playername . $playerscore . $playerlevel . $difficulty);

    // TRE : TR ERROR MESSAGE's
    // 001 : Wrong MD5 Hash
    // 002 : Wrong Username
    // 003 : Wrong Password
    // 004 : Wrong User or Pass
    // 005 : DATA BASE ERROR
    // 006 : DONE
  
    if($md5hash !== $md5) {
        // Wrong MD5.
        echo ("TRE:001");
    }else{
        // Check the Game name and password first
        //Open the link to the database.
        $link = mysql_connect ("Mysql2.streamline.net", "TeamRebellion", "fdesrhgwgd");
        mysql_select_db("TeamRebellion", $link);
        $result_check = mysql_query("SELECT * FROM `Score_games` WHERE `game`='$gamename'", $link) or die ('Entry not found : ' . mysql_error());
        $row_check=mysql_fetch_row($result_check);
      
        if($row_check[6]==$gamepass){
          
            //open a connection to mysql, machine, uid, pwd
          
                //SQL to insert a record
                $query  = "INSERT INTO `Score_scores` ( Game,Owner,Difficulty,Name,Score,Level,ID ) VALUES ('$gamename','$row_check[5]','$difficulty','$playername','$playerscore','$playerlevel','')";
                  
                //$query="INSERT INTO table (date,title,heading,body,posted) VALUES ($date,$title,$heading,$body,$by)";
                $result=mysql_query($query,$link);
                //close the connection
              
                //Done.
                echo ("TRE:006");
        }else{
          
            //Wrong User or pass
            echo ("TRE:004");
          
        }
    }
    mysql_close($link);
?>
 
Top Bottom