It does not make sense to use putenv
, if it is to do this it is better to throw everything in a array
or object
, something like:
config.php
return
is recognized in include
<?php
return (object) array(
'host' => 'localhost',
'user' => 'root',
'pass' => 'meupassword',
'db' => 'meubanco',
);
pagina.php
$config = require 'config.php';
$con = new mysqli($config->host, $config->user, $config->pass, config->banco);
The issue of security
Perhaps this story that you have heard that getenv
is safer is if setting refers to setting such data out of .php
, in environment variables to be more accurate, I will not enter into discussion merit about this , because it does not make much sense, the variables will be accessible to any application in any way, either way, using a array/object
or using the problem is not in your phps and yes in your server.
Now if your fear is that someone gets access to .php
, using putenv
will not solve anything.
In short, if your fear is some user via internet accessing the password somehow use getenv
is not solution, it is impossible for the visitor to have access to this data unless you have exposed them with echo
print
, print_r
or some very bad debugger (it is strongly recommended to turn off debuggers on the production server ).