Skip to content

Instantly share code, notes, and snippets.

@hirthwork
Created January 17, 2015 08:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hirthwork/bcc3b9524f708fff4751 to your computer and use it in GitHub Desktop.
Save hirthwork/bcc3b9524f708fff4751 to your computer and use it in GitHub Desktop.
i2p-proxy.php
<?php
function headerfunc($ch, $str){
header($str);
return strlen($str);
}
function writefunc($ch, $str){
print $str;
flush();
return strlen($str);
}
$url = 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
$curlSession = curl_init();
curl_setopt($curlSession, CURLOPT_URL, $url);
curl_setopt($curlSession, CURLOPT_HEADER, false);
if (preg_match("/[.]i2p$/", $_SERVER['HTTP_HOST']) == 1) {
curl_setopt($curlSession, CURLOPT_PROXY, '10.100.0.1:4444');
}
curl_setopt($curlSession, CURLOPT_HEADERFUNCTION, 'headerfunc');
curl_setopt($curlSession, CURLOPT_WRITEFUNCTION, 'writefunc');
curl_setopt($curlSession, CURLOPT_RETURNTRANSFER, false);
curl_setopt($curlSession, CURLOPT_TIMEOUT, 300);
curl_setopt($curlSession, CURLOPT_FOLLOWLOCATION, 1);
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
$postinfo = file_get_contents('php://input');
curl_setopt ($curlSession, CURLOPT_POST, 1);
curl_setopt ($curlSession, CURLOPT_POSTFIELDS, $postinfo);
}
curl_exec ($curlSession);
if (curl_error($curlSession)) {
print curl_error($curlSession);
}
curl_close ($curlSession);
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment