3 * PHP proxy script that proxies the URL given in the "url" parameter.
5 * Sends all incoming headers, and also returns all remote headers.
6 * Streams the response, so that large responses should work fine.
8 * @author Christian Weiske <cweiske@cweiske.de>
10 require_once __DIR__ . '/../data/config.php';
11 if (!isset($enablePodcastProxy) || $enablePodcastProxy == false) {
12 header('HTTP/1.0 403 Forbidden');
13 echo "Proxying is not enabled in config.php\n";
17 if (!isset($_GET['url']) || $_GET['url'] == '') {
18 header('HTTP/1.0 400 Bad Request');
19 echo "url parameter missing\n";
22 if (substr($_GET['url'], 0, 7) != 'http://'
23 && substr($_GET['url'], 0, 8) != 'https://'
25 header('HTTP/1.0 400 Bad Request');
26 echo "Only http and https URLs supported\n";
32 //send original http headers
34 foreach (apache_request_headers() as $name => $value) {
35 if (strtolower($name) == 'host') {
38 $headers[] = $name . ': ' . $value;
40 $context = stream_context_create(
41 ['http' => ['header' => $headers, 'ignore_errors' => true]]
44 $fp = fopen($url, 'r', false, $context);
46 header('HTTP/1.0 400 Bad Request');
47 echo "Error fetching URL\n";
51 //send original headers
52 if (is_array($http_response_header)) {
53 foreach ($http_response_header as $header) {
58 //stream the data in 1kiB blocks
60 echo fread($fp, 1024);