Created
April 3, 2009 15:16
-
-
Save hubgit/89783 to your computer and use it in GitHub Desktop.
Adding HTTP authentication parameters to a URL, proxying the result
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 | |
$url = $_GET['url']; | |
$cookie = $_GET['cookie']; | |
$parts = parse_url($url); | |
$parts['user'] = $auth[$parts['host']]['user']; | |
$parts['pass'] = $auth[$parts['host']]['pass']; | |
$url = construct_url($parts); | |
//print $url; | |
$headers = array("Cookie: $cookie"); | |
$context['http']['header'] = implode("\r\n", $headers) . "\r\n"; | |
set_time_limit(0); | |
$s = fopen($url, 'rb', false, stream_context_create($context)); | |
foreach ($http_response_header as $h) | |
header($h); | |
while (!feof($s)) | |
echo fread($s, 4096); | |
fclose($s); | |
function construct_url($p){ | |
$uri = ''; | |
if (isset($p['scheme'])) | |
$uri = $p['scheme'] . '://'; | |
if (isset($p['user'])){ | |
$uri .= $p['user']; | |
if (isset($p['pass'])) | |
$uri .= ':' . $p['pass']; | |
$uri .= '@'; | |
} | |
if (isset($p['host'])) | |
$uri .= $p['host']; | |
if (isset($p['port'])) | |
$uri .= ':' . $p['port']; | |
if (isset($p['path'])){ | |
if (substr($p['path'], 0, 1) != '/') | |
$uri .= '/'; | |
$uri .= $p['path']; | |
} | |
if (isset($p['query'])) | |
$uri .= '?' . $p['query']; | |
if (isset($p['fragment'])) | |
$uri .= '#' . $p['fragment']; | |
return $uri; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment