I'm a relative newbee so please be gentle!
I've arrived at the following code for accessing a web page through a proxy:
The file in which this code is held needs to be accessed by calling a url such as "http://www.myhost.com/proxy?url=htp://www.yahoo.com"
The idea is that I get the code returned from the yahoo front page (in this instance) via the proxy.
<?
$proxy = "<<<<insert ip address>>>>";
$port = "<<<<insert port#>>>>" ;
$fp = fsockopen($proxy, $port);
fputs($fp, "GET $url HTTP/1.0\r\nHost: $proxy\r\n\r\n");
echo "$fp";
echo "stuff";
while(!feof($fp)){
$line = fgets($fp, 4000); print($line); }
fclose($fp);
?>
I got all this by trial and error so I'd welcome suggestions for improvements from people who know what they're doing! I'm sure I'l be making some basic school-boy errors!
In particular, I have two questions:
1) Some sites won't respond. It seems that they need some sort of data to say that a real web browser is accessing the page. My question is - how would I transmit data via the proxy to suggest to the page I'm visiting that I am IE6 or the like - even though I'm not.
2) I sometimes get a nasty endlessly looping error - presumably if the proxy goes down and I'm therefore getting no data back. Is there a safer way to do this to avoid the dreaded loop?
Thank you for bearing with me. I hope to hear back.
Regards,
Deano.