added a better way to store credentials

This commit is contained in:
Louis Vallat 2019-11-09 23:56:28 +01:00
parent fafedd38f6
commit 4141eaf3ea
3 changed files with 12 additions and 5 deletions

2
.gitignore vendored
View File

@ -1 +1 @@
./assets/php/config.json assets/php/config.json

View File

@ -0,0 +1,7 @@
{
"host":"localhost",
"dbname": "db",
"user": "user",
"password": "pass",
"kind": "mysql"
}

View File

@ -3,11 +3,11 @@
$SESSION_COOKIE_NAME = "connection_id"; $SESSION_COOKIE_NAME = "connection_id";
$MAX_COOKIE_LIFE = time() + 86400 * 30; // 30 days max $MAX_COOKIE_LIFE = time() + 86400 * 30; // 30 days max
$config_array = json_decode(file_get_contents("config.json", true));
$dsn = "mysql:dbname=food-inventory;host=localhost"; $dsn = $config_array->{"kind"} . ":dbname="
$user = 'food-inventory'; . $config_array->{"dbname"} . ";host=" . $config_array->{"host"};
$password = 'xt3apB8uVbFIYJvp'; $PDO = new PDO($dsn, $config_array->{"user"}, $config_array->{"password"});
$PDO = new PDO($dsn, $user, $password);
$PDO->query('SET CHARSET UTF8'); $PDO->query('SET CHARSET UTF8');
function is_https() function is_https()