Closed NielsWarnaar closed 2 years ago
$root = realpath($_SERVER["DOCUMENT_ROOT"]);
$filePath = $root . "/DAL/creds.dat"; # This uses a json file called creds.dat stored 1 folder above the site's root. This makes it inaccessible from the web. It stores the database credentials
$file = fopen($filePath, "r") or die ("<br/> Unable to open credentials");
$fileText = fread($file, filesize($filePath));
fclose($file);
$json = json_decode($fileText, true);
$this->conn = mysqli_connect($json["DB_HOST"], $json["DB_USER"], $json["DB_PASS"], $json["DB_DB"]) or die ("<br/> Could not connect to the SQL server");
In plaats van bovenstaand te gebruiken kunnen we een dotenv file gebruiken. Dit maakt het een stuk makkelijker.
https://github.com/vlucas/phpdotenv
Deze kan geinstalleerd worden via composer.
Prima, zolang het wachtwoord niet zichtbaar is, is het goed. Kijk maar wat het makkelijkst is😉
Het wachtwoord is nu te vinden in de bestanden, aangezien de repo op public staat door de workflow en er bots aan het zoeken zijn naar wachtwoorden kunnen we deze beter verbergen voordat de database kapotgaat.