470,815 Members | 1,097 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,815 developers. It's quick & easy.

HTTP tunneling with PHP (prefereably PHP5)?

Is it possible (i.e. are there any modules out there) that allows one to
do HTTP tunneling from PHP? (Google is only bringing up ASP.NET links)

I'm working with PHP5 so ideally, the code is PHP5 (or at least OO).

tia

Jan 4 '06 #1
4 3367
NC
Paul Dodowa wrote:

Is it possible (i.e. are there any modules out there) that allows
one to do HTTP tunneling from PHP?
Yes. You will need to work with raw HTTP headers, however.
I'm working with PHP5 so ideally, the code is PHP5 (or
at least OO).


It's not that difficult. Basically, all you need to do is to establish
a connection with your proxy server using fsockopen() and then send a
CONNECT request... It's rather straightforward, so you can wrap it up
in all the OOP you want...

Cheers,
NC

Jan 4 '06 #2


NC wrote:
Paul Dodowa wrote:
Is it possible (i.e. are there any modules out there) that allows
one to do HTTP tunneling from PHP?

Yes. You will need to work with raw HTTP headers, however.

I'm working with PHP5 so ideally, the code is PHP5 (or
at least OO).

It's not that difficult. Basically, all you need to do is to establish
a connection with your proxy server using fsockopen() and then send a
CONNECT request... It's rather straightforward, so you can wrap it up
in all the OOP you want...

Cheers,
NC


Hi NC,

Have you got any good links/references that show how this is done?

Cheers mate

Jan 5 '06 #3
NC
Paul Dodowa wrote:
NC wrote:
It's not that difficult. Basically, all you need to do is to establish
a connection with your proxy server using fsockopen() and then send a
CONNECT request... It's rather straightforward, so you can wrap it up
in all the OOP you want...


Have you got any good links/references that show how this is done?


Let's say you want to connect to mail.example.com on port 25 through an
HTTP
tunnel using a proxy server called your.proxy.server:

$host = 'your.proxy.server';
$port = '4480'; // 4480 is the default HTTP proxy port
$fp = fsockopen($host, $port)
or die ("ERROR: Could not connect to proxy server $host on port
$port");
fputs($fp, "CONNECT mail.example.com:25 HTTP/1.0\r\n\r\n");
$response = '';
do {
$line = fgets($fp, 10240);
$response .= $line;
} while (trim($line) <> null);
// Now $response contains the complete response of mail.example.com.
// The response should be parsed to determine whether mail.example.com
// is ready to communicate. If it is, you can start sending requests
to
// mail.example.com using fputs() and read responses using fgets().
fclose ($fp);

Cheers,
NC

Jan 5 '06 #4


NC wrote:
Paul Dodowa wrote:
NC wrote:
It's not that difficult. Basically, all you need to do is to establish
a connection with your proxy server using fsockopen() and then send a
CONNECT request... It's rather straightforward, so you can wrap it up
in all the OOP you want...


Have you got any good links/references that show how this is done?

Let's say you want to connect to mail.example.com on port 25 through an
HTTP
tunnel using a proxy server called your.proxy.server:

$host = 'your.proxy.server';
$port = '4480'; // 4480 is the default HTTP proxy port
$fp = fsockopen($host, $port)
or die ("ERROR: Could not connect to proxy server $host on port
$port");
fputs($fp, "CONNECT mail.example.com:25 HTTP/1.0\r\n\r\n");
$response = '';
do {
$line = fgets($fp, 10240);
$response .= $line;
} while (trim($line) <> null);
// Now $response contains the complete response of mail.example.com.
// The response should be parsed to determine whether mail.example.com
// is ready to communicate. If it is, you can start sending requests
to
// mail.example.com using fputs() and read responses using fgets().
fclose ($fp);

Cheers,
NC

Thanks !

Jan 5 '06 #5

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

7 posts views Thread by Christoph Nothdurfter | last post: by
8 posts views Thread by Rob Ristroph | last post: by
5 posts views Thread by Tim Tyler | last post: by
11 posts views Thread by neur0maniak | last post: by
4 posts views Thread by badbetty | last post: by
5 posts views Thread by Aziz | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.