Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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