-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathallowProxy.php
39 lines (31 loc) · 1.07 KB
/
allowProxy.php
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
<?php
$domainIncludeList = [
'http://localhost:3000',
'https://portalific.com',
];
$allowedHost = $_SERVER['HTTP_ORIGIN'] ?? $_SERVER['HTTP_HOST'];
if (!in_array($allowedHost, $domainIncludeList)) {
http_response_code(401);
echo "<h1>Unauthorized</h1><p>Request host isn't in include list.</p>";
exit();
}
header('Access-Control-Allow-Origin: ' . $allowedHost);
header('Access-Control-Allow-Methods: GET, OPTIONS');
header('Access-Control-Allow-Headers: User-Agent, Authorization, Origin, Content-Type, Accept');
header('Access-Control-Expose-Headers: *');
header('Access-Control-Allow-Credentials: true');
header('Vary: Origin');
if (empty($_GET['url'])) {
http_response_code(412);
echo "<h1>Precondition Failed</h1><p>URL request parameter required.</p>";
exit();
}
$context = stream_context_create(['http' => ['ignore_errors' => true]]);
$result = file_get_contents($_GET['url'], false, $context);
foreach ($http_response_header as $header) {
if (preg_match('(^(Vary|Access-))i', $header)) {
continue;
}
header($header);
}
echo $result;