What are the potential security risks of storing user data in a text file in PHP?
Storing user data in a text file in PHP can lead to security risks such as unauthorized access, data manipulation, and exposure of sensitive information. To mitigate these risks, it is recommended to encrypt the data before storing it in the text file and implement proper access controls to restrict who can read and write to the file.
<?php
// Encrypt user data before storing it in a text file
$userData = "Sensitive user data";
$encryptedData = openssl_encrypt($userData, 'AES-256-CBC', 'secret_key', 0, '16digitIV');
// Store the encrypted data in a text file
$file = fopen("user_data.txt", "w");
fwrite($file, $encryptedData);
fclose($file);
?>