In PHP we can use files to store sensitive data, but those files must have certain levels of protection.
We are going to take the example of a file that stores our login credentials to the database.
To save this important information I have created a db.php.ini
file that contains the following:
<?php return; ?>
; credenciales
host=localhost
usuario=elusuariodeladb
clave="laclave"
dbnombre=elnombredeladb
This file applies several levels of security:
public_html
, so it can not be accessed through the browser .credenciales
<?php return; ?>
so that, if by some chance it is accessed by URL, it does not show anything. The reading of that file, when connecting to the database, is done like this:
private function Connect()
{
/* Leer credenciales desde el archivo ini */
$this->credenciales = parse_ini_file(".credentials/db.php.ini");
$dsn = 'mysql:dbname=' . $this->credenciales["dbnombre"] .
';host=' . $this->credenciales["host"] . '';
$pwd = $this->credenciales["clave"];
$usr = $this->credenciales["usuario"];
// ... más código
}
The question
Are there other measures that could be taken to give this file more security? What would those measures be?