Are there any potential security risks in storing user IDs in a text file on the server?

Storing user IDs in a text file on the server can pose a security risk as the file may be accessible to unauthorized users, leading to potential data breaches or unauthorized access. To mitigate this risk, it is recommended to store sensitive information like user IDs in a secure database with proper access controls.

// Example of storing user IDs in a secure database instead of a text file
$servername = "localhost";
$username = "username";
$password = "password";
$dbname = "myDB";

// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);

// Check connection
if ($conn->connect_error) {
    die("Connection failed: " . $conn->connect_error);
}

// Insert user ID into database
$user_id = "12345";
$sql = "INSERT INTO users (user_id) VALUES ('$user_id')";

if ($conn->query($sql) === TRUE) {
    echo "New record created successfully";
} else {
    echo "Error: " . $sql . "<br>" . $conn->error;
}

$conn->close();