✨ Story 5.4: reCAPTCHA v3
This commit is contained in:
46
includes/config.php
Normal file
46
includes/config.php
Normal file
@@ -0,0 +1,46 @@
|
||||
<?php
|
||||
function loadEnv(string $path): void
|
||||
{
|
||||
if (!file_exists($path)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$lines = file($path, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
|
||||
if ($lines === false) {
|
||||
return;
|
||||
}
|
||||
|
||||
foreach ($lines as $line) {
|
||||
$line = trim($line);
|
||||
if ($line === '' || str_starts_with($line, '#')) {
|
||||
continue;
|
||||
}
|
||||
|
||||
[$key, $value] = array_pad(explode('=', $line, 2), 2, null);
|
||||
if ($key === null || $value === null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$key = trim($key);
|
||||
$value = trim($value);
|
||||
$value = trim($value, "\"'");
|
||||
|
||||
$_ENV[$key] = $value;
|
||||
$_SERVER[$key] = $value;
|
||||
putenv("{$key}={$value}");
|
||||
}
|
||||
}
|
||||
|
||||
function env(string $key, ?string $default = null): ?string
|
||||
{
|
||||
$value = $_ENV[$key] ?? $_SERVER[$key] ?? getenv($key);
|
||||
if ($value === false || $value === null || $value === '') {
|
||||
return $default;
|
||||
}
|
||||
return $value;
|
||||
}
|
||||
|
||||
loadEnv(__DIR__ . '/../.env');
|
||||
|
||||
define('RECAPTCHA_SITE_KEY', env('RECAPTCHA_SITE_KEY', ''));
|
||||
define('RECAPTCHA_SECRET_KEY', env('RECAPTCHA_SECRET_KEY', ''));
|
||||
Reference in New Issue
Block a user