What are the potential security risks associated with storing visitor IP addresses in a text file on the server?

Storing visitor IP addresses in a text file on the server can pose a security risk as it exposes sensitive user data to potential breaches or unauthorized access. To mitigate this risk, it is recommended to encrypt the IP addresses before storing them in the text file. This way, even if the file is accessed by unauthorized parties, the data will remain protected.

// Encrypt the IP address before storing it in the text file
$ip = $_SERVER['REMOTE_ADDR'];
$encrypted_ip = openssl_encrypt($ip, 'AES-128-CBC', 'your_secret_key', 0, 'your_iv');
file_put_contents('ip_addresses.txt', $encrypted_ip . PHP_EOL, FILE_APPEND);