User Tag List

Results 1 to 3 of 3

Thread: Upgrading to PHP 8.1 killed saving scores online

  1. #1
    Clicker Fusion 2.5 (Steam)Fusion 2.5 Developer (Steam)Android Export Module (Steam)HTML5 Export Module (Steam)iOS Export Module (Steam)Universal Windows Platform Export Module (Steam)
    SpaceKoala's Avatar
    Join Date
    Jan 2019
    Posts
    22
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question Upgrading to PHP 8.1 killed saving scores online

    Apparently with upgrading PHP 8.1 a lot of the commands in the score saving php script that Jeff wrote have been depreciated (or annoyingly changed from mysql... to mysqli... and some arguments needing to be added to certain commands.)

    I do not know anything about php or coding in general but I have been trying to update the script by reading the error log, googling the error and changing the line.

    I have fixed most of the errors but now the only errors I get are related to these two array keys not being defined and I have not been able to solve this via google.

    Code:
    [27-Jan-2023 06:41:32 America/Chicago] PHP Warning:  Undefined array key "status" in /home1/(my server name)/public_html/apps/scores/score_script.php on line 78
    [27-Jan-2023 06:41:32 America/Chicago] PHP Warning:  Undefined array key "gameid" in /home1/(my server name)/public_html/apps/scores/score_script.php on line 87
    [27-Jan-2023 06:41:57 America/Chicago] PHP Warning:  Undefined array key "status" in /home1/(my server name)/public_html/apps/scores/score_script.php on line 78
    [27-Jan-2023 06:41:57 America/Chicago] PHP Warning:  Undefined array key "gameid" in /home1/(my server name)/public_html/apps/scores/score_script.php on line 87
    I have pasted the code with my fixes below. Does anyone have any knowledge of PHP 8.1 and able to help out?

    Code:
     
    <?  
    
    // header("Access-Control-Allow-Origin: *");
    
    	///////////////////////////////////////////////////////
    	// Online Score Script
    	// Jeff Vance 
    	// Version 1.4
    	//////////////////////////////////////////////////////
    	
    	//////////////////////////////////////////////////////
    	// WARNING AND READ THIS!
    	// You don't need to edit this file
    	// The only file to edit is config.php
    	// Don't edit this unless you know what your doing :)
    	// This works out of the box -- your error must be in config.php
    	/////////////////////////////////////////////////////
    	
    	// Get Configuation file
    	require("config.php");
    	
    	// Connect to your server
        $db=mysqli_connect($mysql_host,$mysql_user,$mysql_password) or die (mysql_error());
    	@mysqli_select_db($db,$mysql_database) or die (mysql_error());
    
    
    		
    	//////////////////////////////////////////////////
    	// Check for the existing table if its not found create it
    	// This is really just here to make the life of new users of the script eaiser
    	// They won't have to go thru the script and create the table
    	/////////////////////////////////////////////////
    
    	if(!mysqli_num_rows( mysqli_query($db,"SHOW TABLES LIKE '".$tname."'")))
    	{
    	$query = "CREATE TABLE `$tname` (`id` int(11) NOT NULL auto_increment,`gameid` varchar(255) NOT NULL,`playername` varchar(255) NOT NULL,`score` int(255) NOT NULL,`scoredate` varchar(255) NOT NULL,`md5` varchar(255) NOT NULL, PRIMARY KEY  (`id`)) ENGINE=MyISAM AUTO_INCREMENT=1 DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;";
    
    	$create_table = mysql_query($query)or die (mysql_error());
    	// Preload table with 10 scores
    	$date = date('M d Y');
    	
    	$query = "insert into $tname(gameid,playername,score,scoredate) values ('1','Space Koala','100','$date')";
    	$insert_the_data = mysql_query($query)or die(mysql_error());
    	
    	$query = "insert into $tname(gameid,playername,score,scoredate) values ('1','Space Koala','99','$date')";
    	$insert_the_data = mysql_query($query)or die(mysql_error());
    	
    	$query = "insert into $tname(gameid,playername,score,scoredate) values ('1','Space Koala','98','$date')";
    	$insert_the_data = mysql_query($query)or die(mysql_error());
    	
    	$query = "insert into $tname(gameid,playername,score,scoredate) values ('1','Space Koala','97','$date')";
    	$insert_the_data = mysql_query($query)or die(mysql_error());
    	
    	$query = "insert into $tname(gameid,playername,score,scoredate) values ('1','Space Koala','96','$date')";
    	$insert_the_data = mysql_query($query)or die(mysql_error());
    
            $query = "insert into $tname(gameid,playername,score,scoredate) values ('1','Space Koala','95','$date')";
    	$insert_the_data = mysql_query($query)or die(mysql_error());
    	
    	$query = "insert into $tname(gameid,playername,score,scoredate) values ('1','Space Koala','94','$date')";
    	$insert_the_data = mysql_query($query)or die(mysql_error());
    		
    	$query = "insert into $tname(gameid,playername,score,scoredate) values ('1','Space Koala','93','$date')";
    	$insert_the_data = mysql_query($query)or die(mysql_error());
    	
    	$query = "insert into $tname(gameid,playername,score,scoredate) values ('1','Space Koala','92','$date')";
    	$insert_the_data = mysql_query($query)or die(mysql_error());
    	
    	$query = "insert into $tname(gameid,playername,score,scoredate) values ('1','Space Koala','91','$date')";
    	$insert_the_data = mysql_query($query)or die(mysql_error());
    	
    	
    	}
    	
    	///////////////////////////////////////////////////////
    	// Status Checker
    	///////////////////////////////////////////////////////
    	if ($_GET["status"])
    	{
    	echo "online";
    	exit;
    	}
    	
    	////////////////////////////////////////////////////////
    	// Run some checks on our gameid 
    	////////////////////////////////////////////////////////
    	$gameid_safe = mysqli_real_escape_string($db,$_GET["gameid"]);
    	// Check the gameid is numeric
    	// If its not numberic lets exit
    	if(!is_numeric($gameid_safe))
        {
         exit; 
        }
    
    	///////////////////////////////////////////////////////
    	// Upload new score
    	///////////////////////////////////////////////////////
    	// Test for the variables submitted by the player
    	// If they exist upload into the database
    
    	if ($_GET["playername"] && $_GET["gameid"] && $_GET["score"])
    	{
    	
    	// Strip out | marks submitted in the name or score
    	$playername_safe = str_replace("|","_",$_GET["playername"]);
    	
    	//Unsafe name checker
    	$unsafe = explode("\n", file_get_contents('banwords.txt'));
    	$playername_safe = str_ireplace($unsafe, "",$playername_safe);
    
    	$playername_safe = mysqli_real_escape_string($db,$playername_safe);
    	$score_safe = mysql_real_escape_string($_GET["score"]);
    	$date = date('M d Y');
    		
    	// Check the score sent is is numeric
    	// If the score is not numberic lets exit
    	if(!is_numeric($score_safe))
        {
         exit; 
        }
    	
    	// this secret key needs to be the same as the secret key in your game.
    	$security_md5= md5($_GET["gameid"].$_GET["playername"].$_GET["score"].$secret_key);
    	
    	// Check for submitted MD5 different then server generated MD5
    	if ($security_md5 <>$_GET["code"])
    	{
    	// Something is wrong -- MD5 security hash is different
    	// Could be someone trying to insert bogus score data
    	exit;
    	}
    	// Everything is cool -- Insert the data into the database
    	$query = "insert into $tname(gameid,playername,score,scoredate,md5) values ('$gameid_safe','$playername_safe','$score_safe','$date','$security_md5')";
    	$insert_the_data = mysqli_query($db,$query)or die(mysql_error());
    	}
    		
    	///////////////////////////////////////////////////////
    	// List high score
    	///////////////////////////////////////////////////////
    	// Return a list of high scores with "|" as the delimiter
    	if ($gameid_safe)
    	{
        $query = "select * from $tname where gameid='$gameid_safe' order by score desc limit 10";
    	$view_data = mysqli_query($db,$query)or die(mysql_error());
    	while($row_data = mysqli_fetch_array($view_data))
    		{
    		print($row_data["playername"]);
    		print "|";
    		print ($row_data["score"]);
    		print ("|");
    		print($row_data["scoredate"]);
    		print("|");
    		}
    	
    	// We limit the score database to hold the number defined in the config script
    	// First check to see how many records we have for this game
      
    	$query1 ="select * from $tname where gameid = '$gameid_safe'";
    	$countresults = mysqli_query($db,$query1)or die(mysql_error());
    	$countofdeletes = mysqli_num_rows($db,$countresults);
    	if (mysqli_num_rows($db,$countresults)>$score_number)
    		{
    		$query2 ="SELECT * FROM $tname WHERE gameid = '$gameid_safe' ORDER BY score DESC Limit $score_number,$countofdeletes";
    		$Get_data = mysqli_query($db,$query2)or die (mysql_error());
    		while($row_data = mysql_fetch_array($Get_data))
    		{
    		$id_delete = $row_data["id"];
    		$query3 = "Delete from $tname where id = $id_delete";
    		$Delete_data = mysqli_query($db,$query3)or die (mysql_error());
    		}
    		}
    	}
    		
    ?>

  2. #2
    Clicker Fusion 2.5 DeveloperAndroid Export ModuleHTML5 Export ModuleiOS Export Module

    Join Date
    Apr 2012
    Location
    Heidelberg, Germany
    Posts
    34
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I'm working with PHP nearly every day.

    It looks like it is not even PHP 7 compatible. All mysql_... should be mysqli_... (with an i) and some need the database connection in the first parameter ($db) but not the ones you added them

    Everything should work fine now. Please let me know if not.



    PHP Code:
    <?php

    // header("Access-Control-Allow-Origin: *");

    ///////////////////////////////////////////////////////
    // Online Score Script
    // Jeff Vance
    // Version 1.5
    // PHP 7/8 fixes by Sven Bader
    //////////////////////////////////////////////////////

    //////////////////////////////////////////////////////
    // WARNING AND READ THIS!
    // You don't need to edit this file
    // The only file to edit is config.php
    // Don't edit this unless you know what your doing :)
    // This works out of the box -- your error must be in config.php
    /////////////////////////////////////////////////////

    // Get Configuation file
    require("config.php");

    // Connect to your server


    $db mysqli_connect($mysql_host$mysql_user$mysql_password) or die("MySQL Error");
    @
    mysqli_select_db($db$mysql_database) or die (mysqli_error($db));


    //////////////////////////////////////////////////
    // Check for the existing table if it's not found create it
    // This is really just here to make the life of new users of the script easier
    // They won't have to go through the script and create the table
    /////////////////////////////////////////////////

    if (!mysqli_num_rows(mysqli_query($db"SHOW TABLES LIKE '" $tname "'"))) {
        
    $query "CREATE TABLE `$tname` (`id` int(11) NOT NULL auto_increment,`gameid` varchar(255) NOT NULL,`playername` varchar(255) NOT NULL,`score` int(255) NOT NULL,`scoredate` varchar(255) NOT NULL,`md5` varchar(255) NOT NULL, PRIMARY KEY  (`id`)) ENGINE=MyISAM AUTO_INCREMENT=1 DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;";
        
    $create_table mysqli_query($db$query) or die (mysqli_error($db));
        
    // Preload table with $score_number scores
        
    $date date('M d Y');

        for (
    $i 1$i <= $score_number$i++) {
            
    $query "insert into $tname(gameid,playername,score,scoredate) values ('1','Space Koala',101-$i,'$date')";
            
    $insert_the_data mysqli_query($db$query) or die(mysqli_error($db));
        }


    }

    ///////////////////////////////////////////////////////
    // Status Checker
    ///////////////////////////////////////////////////////
    if ($_GET["status"]) {
        echo 
    "online";
        exit;
    }

    ////////////////////////////////////////////////////////
    // Run some checks on our gameid
    ////////////////////////////////////////////////////////

    $gameid_safe intval(mysqli_real_escape_string($db$_GET["gameid"]));


    ///////////////////////////////////////////////////////
    // Upload new score
    ///////////////////////////////////////////////////////
    // Test for the variables submitted by the player
    // If they exist upload into the database

    if ($_GET["playername"] && $_GET["gameid"] && $_GET["score"]) {

        
    // Strip out | marks submitted in the name or score
        
    $playername_safe mysqli_real_escape_string($db$_GET["playername"]);
        
    $playername_safe str_replace("|""_""$playername_safe");

        
    //Unsafe name checker
        
    $unsafe explode("\n"file_get_contents('banwords.txt'));
        
    $playername_safe str_ireplace($unsafe""$playername_safe);


        
    $score_safe mysqli_real_escape_string($db$_GET["score"]);
        
    $score_safe intval($score_safe);

        
    $date date('M d Y');

        
    // this secret key needs to be the same as the secret key in your game.
        
    $security_md5 md5($_GET["gameid"] . $_GET["playername"] . $_GET["score"] . $secret_key);

        
    // Check for submitted MD5 different then server generated MD5
        
    if ($security_md5 <> $_GET["code"]) {
            
    // Something is wrong -- MD5 security hash is different
            // Could be someone trying to insert bogus score data
            
    exit;
        }
        
    // Everything is cool -- Insert the data into the database
        
    $query "insert into $tname(gameid,playername,score,scoredate,md5) values ('$gameid_safe','$playername_safe','$score_safe','$date','$security_md5')";
        
    $insert_the_data mysqli_query($db$query) or die(mysqli_error($db));
    }

    ///////////////////////////////////////////////////////
    // List high score
    ///////////////////////////////////////////////////////
    // Return a list of high scores with "|" as the delimiter
    if ($gameid_safe) {
        
    $query "select * from $tname where gameid='$gameid_safe' order by score desc limit " $score_number;
        
    $view_data mysqli_query($db$query) or die(mysqli_error($db));
        while (
    $row_data mysqli_fetch_array($view_data)) {
            print(
    $row_data["playername"]);
            print 
    "|";
            print (
    $row_data["score"]);
            print (
    "|");
            print(
    $row_data["scoredate"]);
            print(
    "|");
        }

        
    // We limit the score database to hold the number defined in the config script
        // First check to see how many records we have for this game

        
    $query1 "select * from $tname where gameid = '$gameid_safe'";
        
    $countresults mysqli_query($db$query1) or die(mysqli_error($db));
        
    $countofdeletes mysqli_num_rows($countresults);

        if (
    mysqli_num_rows($countresults) > $score_number) {
            
    $query2 "SELECT * FROM $tname WHERE gameid = '$gameid_safe' ORDER BY score DESC Limit $score_number,$countofdeletes";
            
    $Get_data mysqli_query($db$query2) or die (mysqli_error($db));
            while (
    $row_data mysqli_fetch_array($Get_data)) {
                
    $id_delete $row_data["id"];
                
    $query3 "Delete from $tname where id = $id_delete";
                
    $Delete_data mysqli_query($db$query3) or die (mysqli_error($db));
            }
        }
    }

  3. #3
    Clicker Fusion 2.5 (Steam)Fusion 2.5 Developer (Steam)Android Export Module (Steam)HTML5 Export Module (Steam)iOS Export Module (Steam)Universal Windows Platform Export Module (Steam)
    SpaceKoala's Avatar
    Join Date
    Jan 2019
    Posts
    22
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Brilliant! Thank you!

Similar Threads

  1. Online Scores Works on Some PCs but not all
    By piscesdreams in forum Fusion 2.5
    Replies: 13
    Last Post: 4th April 2015, 05:34 PM
  2. A Guide to saving high scores online
    By Jeff in forum Clickteam Guides, Tutorials and Examples
    Replies: 1
    Last Post: 4th June 2014, 01:30 PM
  3. Online Scores help
    By Redsquirrel in forum Fusion 2.5
    Replies: 9
    Last Post: 14th March 2014, 02:25 PM
  4. Online high scores
    By MJK in forum iOS Export Module Version 2.0
    Replies: 12
    Last Post: 23rd August 2011, 05:46 PM
  5. Freehost10.com with online hi scores?
    By RickyRombo in forum Multimedia Fusion 2 - Technical Support
    Replies: 2
    Last Post: 26th April 2009, 03:07 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •