Use fsockopen with proxy

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
klevis miho
Forum Contributor
Posts: 413
Joined: Wed Oct 29, 2008 2:59 pm
Location: Albania
Contact:

Use fsockopen with proxy

Post by klevis miho »

Is it possible to use fsockopen by using a proxy server?
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: Use fsockopen with proxy

Post by requinix »

To the question you're asking, no. A proxy server will not help you use fsockopen.

To the question you're trying to ask, yes. Point fsockopen to the proxy and modify your request headers respectively.
klevis miho
Forum Contributor
Posts: 413
Joined: Wed Oct 29, 2008 2:59 pm
Location: Albania
Contact:

Re: Use fsockopen with proxy

Post by klevis miho »

Thnx tasairis, but can you give me an example on how to do this?
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: Use fsockopen with proxy

Post by requinix »

First learn how to send HTTP requests with fsockopen. Try a search engine.

Then (this is going from memory here) you need to:
- connect to the proxy address and port instead of the destination server
- use the full URL, with protocol and domain and everything, in the GET/POST line
- use a Proxy-Connection: instead of a regular Connection:
klevis miho
Forum Contributor
Posts: 413
Joined: Wed Oct 29, 2008 2:59 pm
Location: Albania
Contact:

Re: Use fsockopen with proxy

Post by klevis miho »

I did this

$ip = "221.130.7.227"; // proxy IP, change this according to your proxy setting in your IE or NS
$port = 80; // proxy port, change this according to your proxy setting in your IE or NS

$fp = fsockopen($ip,$port); // connect to proxy
fputs($fp, "GET translate_tools Http1.1 Host: http://www.translate.google.com/ User-Agent: Mozilla/4.0 (compatible; MSIE 5.5; Windows NT 4.0)");

$data="";
while (!feof($fp)) $data.=fgets($fp,64000);
fclose($fp);

print $data;

Am I missing something here?
Post Reply