Proxy Anonymizer With PHP and cURL

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Gadgetmo
Forum Newbie
Posts: 14
Joined: Sun Nov 01, 2009 7:17 am

Proxy Anonymizer With PHP and cURL

Post by Gadgetmo »

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:

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>";
}
?>
but it doesn't work...

Help!
Post Reply