English 中文(简体)
如何应对CURL 403禁止的错误?
原标题:How to deal with CURL 403 forbidden error ? any solutions?
  • 时间:2012-05-24 13:06:45
  •  标签:
  • php
  • curl

我正使用多曲线从远程站点获取数据。 我的脚本就像

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

它让我回403 禁止回应。

事先感谢大家的建议和评论。

最佳回答

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]);
}
问题回答

联系所有你试图连接的网站的负责人 并问他们为什么禁止你的请求

然后,你可以要么停止(如果他们只是认为你所做的是无法接受的),要么改变请求,使之符合他们的规则。

尝试设置引用者和用户代理信头, 但是!

... 设置 CURLOPT_ SSL_ VERIFYPEER 假冒是危险的, 并且永远不应该在生产中完成。 将这条线至少以某种标准检查方式包装在某类检查中 。

您这样做违反了SSL的目的, 使攻击者能够拦截您的请求并归还他们喜欢的东西, 而不核实他们的SSL证书 。

我通过将 < 强 > 移动到线 下解决问题

curl_setopt($ch, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V4 );




相关问题
Brute-force/DoS prevention in PHP [closed]

I am trying to write a script to prevent brute-force login attempts in a website I m building. The logic goes something like this: User sends login information. Check if username and password is ...

please can anyone check this while loop and if condition

<?php $con=mysql_connect("localhost","mts","mts"); if(!con) { die( unable to connect . mysql_error()); } mysql_select_db("mts",$con); /* date_default_timezone_set ("Asia/Calcutta"); $date = ...

定值美元

如何确认来自正确来源的数字。

Generating a drop down list of timezones with PHP

Most sites need some way to show the dates on the site in the users preferred timezone. Below are two lists that I found and then one method using the built in PHP DateTime class in PHP 5. I need ...

Text as watermarking in PHP

I want to create text as a watermark for an image. the water mark should have the following properties front: Impact color: white opacity: 31% Font style: regular, bold Bevel and Emboss size: 30 ...

How does php cast boolean variables?

How does php cast boolean variables? I was trying to save a boolean value to an array: $result["Users"]["is_login"] = true; but when I use debug the is_login value is blank. and when I do ...

热门标签