What are the potential risks of using a txt file for storing data in PHP?

Using a txt file for storing data in PHP can pose security risks, as the file may be accessible to anyone who has access to the server. To mitigate this risk, it is recommended to store sensitive data in a secure database instead.

// Example of storing data in a txt file securely using PHP
$filename = 'data.txt';
$data = "Some sensitive data";

// Encrypt the data before writing it to the file
$encrypted_data = encrypt_function($data);

// Write the encrypted data to the file
file_put_contents($filename, $encrypted_data);