What are some best practices for scripting an "Online Stats" system using PHP and .Dini files?

Issue: When creating an "Online Stats" system using PHP and .Dini files, it is important to follow best practices to ensure data integrity and security. One way to achieve this is by properly sanitizing user input before storing it in the .Dini files to prevent SQL injection attacks and other security vulnerabilities. PHP Code Snippet:

<?php

// Sanitize user input before storing in .Dini file
function sanitize_input($data) {
    $data = trim($data);
    $data = stripslashes($data);
    $data = htmlspecialchars($data);
    return $data;
}

// Example usage:
$username = sanitize_input($_POST['username']);
$score = sanitize_input($_POST['score']);

// Store sanitized data in .Dini file
$filename = 'stats.dini';
$file = fopen($filename, 'a');
fwrite($file, "Username: $username, Score: $score\n");
fclose($file);

?>