-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathproxy.php
More file actions
49 lines (40 loc) · 1.26 KB
/
Copy pathproxy.php
File metadata and controls
49 lines (40 loc) · 1.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
<?php
$envFile = __DIR__ . '/.env';
function loadEnvFile($path) {
if (!file_exists($path)) {
return;
}
$lines = file($path, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
foreach ($lines as $line) {
if (strpos(trim($line), '#') === 0) {
continue;
}
$parts = explode('=', $line, 2);
if (count($parts) !== 2) {
continue;
}
$name = trim($parts[0]);
$value = trim($parts[1]);
if ((substr($value, 0, 1) === '"' && substr($value, -1) === '"') ||
(substr($value, 0, 1) === "'" && substr($value, -1) === "'")) {
$value = substr($value, 1, -1);
}
putenv("$name=$value");
$_ENV[$name] = $value;
$_SERVER[$name] = $value;
}
}
loadEnvFile($envFile);
$appid = getenv('WEATHER_API_KEY') ?: '';
if ($appid === '') {
http_response_code(500);
echo json_encode(['message' => 'WEATHER_API_KEY is not set']);
exit;
}
header("Content-type: application/json\n\n");
$params = $_SERVER['QUERY_STRING'];
$host = "https://api.openweathermap.org/data/2.5/weather?$params&APPID=$appid";
$ch = curl_init($host);
curl_exec($ch);
curl_close($ch);
?>