Proxy Anonymizer With PHP and cURL
Posted: Tue Dec 22, 2009 7:15 am
I'm trying to build a proxy anonymizer with PHP and cURL. It works fine but I can't get it to change links so they lead to the proxy anonymizer (eg. instead of going to http://example.com/info.html, it would lead to http://website.com/proxy/?url=example.com/info.html). I did this:
but it doesn't work...
Help!
Code: Select all
<?php
if (isset($_GET['submit'])) {
echo "<div id='container'><br />";
$curl_handle=curl_init();
curl_setopt($curl_handle,CURLOPT_URL, $_GET['url']);
curl_setopt($curl_handle,CURLOPT_CONNECTTIMEOUT,2);
curl_setopt($curl_handle,CURLOPT_RETURNTRANSFER,1);
$buffer = curl_exec($curl_handle);
curl_close($curl_handle);
if (empty($buffer))
{
echo "<span id='buffer'>We couldn't find that website...</span>";
}
else
{
# print $buffer;
$dom = new DOMDocument();
@$dom->loadHTML($buffer);
$xpath = new DOMXPath($dom);
$hrefs = $xpath->evaluate("/html/body//a");
function changeLink($url) {
$newurl="?url=".$url."&submit=submit";
$url=$newurl;
}
for ($i = 0; $i < $hrefs->length; $i++) {
$href = $hrefs->item($i);
$url = $href->getAttribute('href');
changeLink($url);
}
print $href;
}
echo "</div>";
}
?>Help!