Created
August 5, 2013 09:22
-
-
Save bsingr/6154573 to your computer and use it in GitHub Desktop.
php script to proxy a feed from feedblitz including stylesheet (for browsers like chrome)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
require('proxy.php'); | |
// feed delivery service | |
$response = proxy_request('feeds.feedblitz.com', '/example-blog'); | |
// rewrite stylesheet | |
$original_style = "feeds.feedblitz.com/feedblitz_rss.xslt"; | |
$fake_style = "example.com/rss.xslt"; | |
$rewritten = str_replace($original_style, $fake_style, $response[content]); | |
// output | |
forward_headers($response['header']); | |
echo $rewritten; | |
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function proxy_request($host, $path) { | |
$remote = fsockopen($host, 80, $errno, $errstr, 30); // open socket port 80 | |
if ($remote){ | |
fputs($remote, "GET $path HTTP/1.1\r\n"); | |
fputs($remote, "Host: $host\r\n"); | |
fputs($remote, "Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7\r\n"); | |
$requestHeaders = apache_request_headers(); | |
while ((list($header, $value) = each($requestHeaders))) { | |
if ($header !== "Connection" && $header !== "Host" && $header !== "Content-length") { | |
fputs($remote, "$header: $value\r\n"); | |
} | |
} | |
fputs($remote, "Connection: close\r\n\r\n"); | |
$result = ''; | |
while (!feof($remote)) { $result .= fgets($remote, 128); } | |
fclose($remote); | |
$result = explode("\r\n\r\n", $result, 2); | |
return array('header' => isset($result[0]) ? $result[0] : '', | |
'content' => isset($result[1]) ? $result[1] : ''); | |
} else { | |
return array('error' => "$errstr ($errno)"); | |
} | |
} | |
function forward_headers($headers) { | |
foreach(explode("\r\n", $headers) as $headerLine) { | |
header($headerLine); | |
} | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment