Some very small applications that do not require a database such as MySQL or Firebird can store data in TXT files.

First, pay attention to where the root of the web server is. For example, Apache2 on Ubuntu uses the path /var/www/html by default.

If this is your case, consider storing the data outside this directory tree, for example, /data or /var/www/data.

Assuming your application requires a username and password to access the page, use the same password as part of the hash for encryption. This prevents one user from having the same decryption hash as another (unless they use the same password).

<?php 
$password = 'a1b2c3d4'; 
$message = "This is the unencrypted message."; 

// SHOWING THE MESSAGE NOT ENCRYPTING YET 
echo $message.'<br><br>'; 

// ENCRYPTING THE VARUABLE $MESSAGE 
$cipher_method = 'aes-128-ctr'; 
$enc_key = openssl_digest(sha1($password), 'SHA256', TRUE); 
$enc_iv = openssl_random_pseudo_bytes(openssl_cipher_iv_length($cipher_method)); 
$crypted_message = openssl_encrypt($message, $cipher_method, $enc_key, 0, $enc_iv) . "::" . bin2hex($enc_iv); 
unset($token, $cipher_method, $enc_key, $enc_iv); 

// SHOWING MESSAGE ALREADY ENCRYPTED 
echo $crypted_message.'<br><br>'; 

// DECRYPTING THE MESSAGE 
list($crypted_token, $enc_iv) = explode("::", $crypted_message);
$cipher_method = 'aes-128-ctr'; 
$enc_key = openssl_digest(sha1($password), 'SHA256', TRUE); 
$message = openssl_decrypt($crypted_token, $cipher_method, $enc_key, 0, hex2bin($enc_iv)); 
unset($crypted_token, $cipher_method, $enc_key, $enc_iv); 

// SHOWING THE MESSAGE DECRYPTED AGAIN 
echo $message; 
?>

Note that the variable ‘$password‘ is part of the hash and will be different for every user. If someone has access to the code, they will not have all the pieces of the puzzle needed to decrypt the data.

Feel free to copy, paste, and run the code above to see how it works.