HTTP request with proxy

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View

I am working on a project to access a web page through a proxy. I do
not host the script myself, but upload it to my hosting provider. The
version of PHP on that server is 4.4.6.

I have attempted using fsockopen as well as cURL to accomplish this
task, but it won't seem to work. Here is the important bits of the
code I am using:

$ch = curl_init();
curl_setopt( $ch, CURLOPT_HTTPPROXYTUNNEL, 1 );
curl_setopt( $ch, CURLOPT_PROXY, $proxy . ":" . $port );
curl_setopt( $ch, CURLOPT_URL, $url );
curl_setopt( $ch, CURLOPT_FOLLOWLOCATION, 1 );
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, 1 );
if( !curl_exec( $ch ) ) {
  echo "<font color=red>Error</font>";

I can't understand why it doesn't work, but all I ever get back is the
error. I have tried several proxies and ports, and they all return the
same message.

In researching the problem, I thought I was on to something when I
read that the host could have a firewall in place to block
connections. My host had, in fact, done this and required having a
dedicated IP in order to bypass the firewall. I paid for the dedicated
IP and now have it configured that way, but I'm still getting an

Oh, BTW, I had it echo curl_getinfo( $ch, CURLINFO_HTTP_CODE ) in
place of the error message, but all I got back was "0", which -
obviously - is not a valid HTTP code.

Any help you can provide will be appreciated. Feel free to respond via
e-mail or the group, as I will be checking both frequently until this
is resolved.

Thanks in advance.


Re: HTTP request with proxy

Tim Arview wrote:
Quoted text here. Click to load it


Try curl_error() here to get a better errordesription.

Also, some proxies demand a username/password. Could this be the case?

Quoted text here. Click to load it

Talk with your ISP about this.

Quoted text here. Click to load it

Good luck.
Maybe you get luckier with curl_error().

Erwin Moller

Re: HTTP request with proxy


on 10/02/2007 12:10 AM Tim Arview said the following:
Quoted text here. Click to load it

Maybe the proxy requires authentication.

You may want to take a look at this HTTP client class. It supports
proxies and authentication too. If you still have a problem, at least
the class can output debug information with the HTTP dialog so you can
see why it fails:


Manuel Lemos

Metastorage - Data object relational mapping layer generator

PHP Classes - Free ready to use OOP components written in PHP

Site Timeline