Reputation:
I am using multi curl to fetch data from remote site. My script is like
foreach ($urls as $i => $url) {
$ch[$i] = curl_init($url['url']);
curl_setopt($ch[$i], CURLOPT_TIMEOUT, 0);
curl_setopt($ch[$i], CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch[$i], CURLOPT_CONNECTTIMEOUT, 0);
curl_setopt($ch[$i], CURLOPT_SSL_VERIFYPEER, false);
curl_multi_add_handle($multiCurlHandler, $ch[$i]);
}
It returns me 403 forbidden in response.
Thanks in advance for suggestions and comments.
Upvotes: 9
Views: 41803
Reputation: 2033
I solve problem by removing below line
curl_setopt($ch, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V4 );
Upvotes: 0
Reputation: 28529
Sanjay's answer may always help. But when the client IP is blocked by the sever side, execute curl in the client side also get this error.
Upvotes: 0
Reputation: 191
Try setting the Referer and User-Agent headers, but!
... setting CURLOPT_SSL_VERIFYPEER to false is dangerous, and should never be done in production. Wrap that line in a is_dev check of some kind at a minimum.
You are defeating the purpose of SSL by doing so, allowing an attacker to intercept your request and return what they like without verifying their SSL certificate.
Upvotes: 1
Reputation: 943567
Contact whomever runs the site you are trying to connect to and ask them why your request is being forbidden.
You can then either stop (if what you are doing is simply deemed unacceptable by them) or change the request so that it conforms to their rules.
Upvotes: 1
Reputation: 1590
Just try by adding two lines for User agents, and see if it works or not. Some servers not accept the requests from scripts, it depends on user agents.
// line 1
$agent = 'Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 1.0.3705; .NET CLR 1.1.4322)';
foreach ($urls as $i => $url) {
$ch[$i] = curl_init($url['url']);
curl_setopt($ch[$i], CURLOPT_TIMEOUT, 0);
curl_setopt($ch[$i], CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch[$i], CURLOPT_CONNECTTIMEOUT, 0);
// line 2
curl_setopt($ch[$i], CURLOPT_USERAGENT, $agent);
curl_setopt($ch[$i], CURLOPT_SSL_VERIFYPEER, false);
curl_multi_add_handle($multiCurlHandler, $ch[$i]);
}
Upvotes: 17