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

curl, php

Solution

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]);
}

Problem

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.

Original source