Jump to content

Can't Use PHP CURL Help ????


aabid

Recommended Posts

Hey Guys,

 

Am developing a script which will send a request to a server through PHP's CURL using proxy, but I don't know why requests are not passing through whenever I use use proxy option of CURL.

And when I remove that proxies everything works fine,

Here is the code,

function getit($url, $start, $msg = "")
{
$ch = curl_init();
curl_setopt($ch, CURLOPT_USERAGENT, "User-Agent: Mozilla/5.0 (SymbianOS/9.1; U; [en-us]) AppleWebKit/413 (KHTML, like Gecko) Safari/413");
curl_setopt($ch, CURLOPT_URL, $url );
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Expect:'));
curl_setopt($ch, CURLOPT_HEADER, 1);
curl_setopt($ch, CURLOPT_HTTPPROXYTUNNEL, 0); 
curl_setopt($ch, CURLOPT_PROXY, $this->proxy);
curl_setopt($ch, CURLOPT_PROXYUSERPWD, 'user:pass');
curl_setopt($ch, CURLOPT_PROXYAUTH, 'CURLPROXY_BASIC');
curl_setopt($ch, CURLOPT_PROXYTYPE, 'CURLAUTH_BASIC');
if(!$start)
{
	curl_setopt($ch, CURLOPT_POST, TRUE);
}
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_AUTOREFERER, true);
curl_setopt($ch, CURLOPT_ENCODING, "" );
if($msg)
	{
	$msg = str_replace(" ", "+", $msg);
	$msg = "msg=".$msg."&".$this->unique;
	curl_setopt($ch, CURLOPT_POSTFIELDS, $msg);
	}
else
	{
	if(!$start)
	{
	curl_setopt($ch, CURLOPT_POSTFIELDS, $this->unique);
	}
	}
curl_setopt($ch, CURLOPT_HTTPHEADER, Array("Content-Type: application/x-www-form-urlencoded","Accept: */*"));
$this->content = curl_exec($ch);
if(!$this->content)
	{
	echo "Requests are not passing through\n";
	echo "Error ".curl_error($ch)."\n";
	}
return $this->content;
}

 

I've searched and tried everything but still not working, please help me to get rid of it :(

Link to comment
Share on other sites

Ya cURL is active in php.ini function and also its working when am not using proxies so no question about that.

 

However how would I know whether its a HTTP proxy or not ? All I know is 3 type of proxies public, private and anonymous. I know for sure that the one am using is anonymous proxy.

 

Would it be a problem ?

Link to comment
Share on other sites

Are you sure it's an HTTP proxy?

 

What curl errors are you getting? Probably connection failures.

 

Am getting this error

ERROR

The requested URL could not be retrieved

 

The following error was encountered while trying to retrieve the URL: http://www.yahoo.com

 

    Access Denied.

 

Access control configuration prevents your request from being allowed at this time. Please contact your service provider if you feel this is incorrect.

 

Your cache administrator is webmaster.

 

Generated Tue, 05 Jul 2011 19:30:02 GMT by funky_blue (squid/3.0.STABLE19)

Link to comment
Share on other sites

There you go. Proxy won't let you connect.

 

Is this a public proxy, or one you've paid for? Your best bet is to ask whoever is providing you this proxy how to cURL through it.

 

HTTP proxy is a proxy that allows communication over the HTTP protocol

Link to comment
Share on other sites

There you go. Proxy won't let you connect.

 

Is this a public proxy, or one you've paid for? Your best bet is to ask whoever is providing you this proxy how to cURL through it.

 

HTTP proxy is a proxy that allows communication over the HTTP protocol

 

but when am using that through my firefox it works and I can surf easily but why not in PHP script ??? I know for sure that its a anonymous proxy...Do I need more information than that ?

Link to comment
Share on other sites

Possibly the authorization. Is it needed?

 

I don't know what authorization means but in my knowledge it is providing valid username and password I assume and am providing that.

Beside that I've also tried to both include and remove following line,

curl_setopt($ch, CURLOPT_PROXYAUTH, 'CURLPROXY_BASIC');

curl_setopt($ch, CURLOPT_PROXYTYPE, 'CURLAUTH_BASIC');

yet also nothing works and it shows the same.

 

What I noticed though is when I comment out the line containing CURLOPT_PROXYUSERPWD, still the error remains same or atleast it looks same in browser output. Might be because of that but am not sure....

Link to comment
Share on other sites

You'll have to check with the owner of the proxy.

 

This isn't a PHP issue, and it is well beyond anything we can help you with. The most I can do is, 'try this, try that, etc'

 

For some reason, the proxy server is rejecting your attempt to cURL through it.

Link to comment
Share on other sites

AM tired with this thing now, can't devise a solution for this. I don't know why the proxy is refusing connection when am trying that with my script.

 

I asked from my proxy provider how to curl and he simply sent me PHP code which was almost same as of mine with no help.

 

I also sent a basic base64 of my username:password in a header to make it authorized still its refusing connections.

 

Please help me guys..... :confused:

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.