How to deal with the forbidden error CURL 403? any solutions?

I use multi curl to retrieve data from a 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]); } 

He returns me 403 in response.

Thanks in advance for suggestions and comments.

+6
source share
4 answers

Just try adding two lines for user agents and see if this works or not. Some servers do not accept 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]); } 
+9
source

Contact the manufacturer of the site you are trying to connect to and ask them why your request is denied.

Then you can either stop (if what you are doing is simply considered unacceptable by them), or change the request to fit their rules.

+1
source

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 this line in an is_dev check at least.

You violate the purpose of SSL by doing this, allowing an attacker to intercept your request and return what they like without checking their SSL certificate.

0
source

Sanjay answer can always help. But when the client IP is blocked by the chest side, running curl on the client side also causes this error.

0
source

Source: https://habr.com/ru/post/916560/


All Articles