32 lines
897 B
PHP
32 lines
897 B
PHP
<?php
|
|
/**
|
|
* Simple .env Loader
|
|
*/
|
|
|
|
// Primary environment file path as requested
|
|
$envFile = '/home/intaleqapp-musadaq/env/.env';
|
|
|
|
// Fallback for local development if the primary server path doesn't exist
|
|
if (!file_exists($envFile)) {
|
|
$envFile = ROOT_PATH . '/.env';
|
|
}
|
|
|
|
if (file_exists($envFile)) {
|
|
$lines = file($envFile, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
|
|
foreach ($lines as $line) {
|
|
if (str_starts_with(trim($line), '#')) continue;
|
|
|
|
$parts = explode('=', $line, 2);
|
|
if (count($parts) !== 2) continue;
|
|
|
|
$name = trim($parts[0]);
|
|
$value = trim($parts[1], " \t\n\r\0\x0B\"'");
|
|
|
|
if (!array_key_exists($name, $_SERVER) && !array_key_exists($name, $_ENV)) {
|
|
putenv(sprintf('%s=%s', $name, $value));
|
|
$_ENV[$name] = $value;
|
|
$_SERVER[$name] = $value;
|
|
}
|
|
}
|
|
}
|