PHP CURL GET 403 禁止
Posted
技术标签:
【中文标题】PHP CURL GET 403 禁止【英文标题】:PHP CURL GET 403 forbidding 【发布时间】:2020-09-07 12:15:18 【问题描述】:我已经安装了一个带有 php 版本 7.4.3 的新 ubuntu 服务器 v20,以从带有 PHP 版本 7.0 的旧 ubuntu 服务器 v18 移动 Web 应用程序,我在执行 CURL REST API GET 时在新服务器上收到 403 错误. Bellow 是带有错误调试的代码,部分许可证密钥已针对帖子进行了修改。我无法在现有帖子中找到与此搜索相关的任何内容。提前感谢您的帮助
ob_start();
$out = fopen('php://output', 'w');
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => "http://license.cmadsystems.com?lic=P9xP1o7USRLkS591cFzBbLSmI9ZTtvR7xgfr86dtYiCZuhy",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_USERAGENT => "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:53.0) Gecko/20100101 Firefox/53.0",
CURLOPT_TIMEOUT => 0,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_VERBOSE => true,
CURLOPT_STDERR => $out,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "GET",
CURLOPT_HTTPHEADER => array(
"Content-Type: application/json"
),
));
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
fclose($out);
$debug = ob_get_clean();
echo $response;
echo $err;
echo $debug;
<!DOCTYPE html PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html><head>
<title>403 Forbidden</title>
</head><body>
<h1>Forbidden</h1>
<p>You don't have permission to access this resource.</p>
<p>Additionally, a 404 Not Found
error was encountered while trying to use an ErrorDocument to handle the request.</p>
</body></html>
* Trying 216.250.121.144:80...
* TCP_NODELAY set
* Connected to license.cmadsystems.com (216.250.121.144) port 80 (#0)
> GET /?lic= P9xP1o7USRLkS591cFzBbLSmI9ZTtvR7xgfr86dtYiCZuhy HTTP/1.1
Host: license.cmadsystems.com
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:53.0) Gecko/20100101 Firefox/53.0
Accept: */*
Accept-Encoding: deflate, gzip, br
Content-Type: application/json
* Mark bundle as not supporting multiuse
< HTTP/1.1 403 Forbidden
< Content-Type: text/html; charset=iso-8859-1
< Transfer-Encoding: chunked
< Connection: keep-alive
< Keep-Alive: timeout=15
< Date: Wed, 20 May 2020 23:45:29 GMT
< Server: Apache
< Content-Encoding: gzip
<
* Connection #0 to host license.cmadsystems.com left intact
【问题讨论】:
2020 年通过 HTTP 进行许可证检查?我的天啊!在我的浏览器中,我得到了 200,即使你的许可证失效了。你能用 file_get_contents 仔细检查一下吗? 它有点也适合我:<br /> <b>Notice</b>: Undefined variable: Lic_Info in <b>/home/u264166153/domains/cmadsystems.com/public_html/license/index.php</b> on line <b>86</b><br /> "status":200,"status_message":"Licensed","data":"Lic_End":null,"Lic_Device":0,"Lic_MOH":0,"Lic_Info":null
可能不需要设置"Content-Type: application/json"
我在本地机器上运行了你的代码,它运行正常!
【参考方案1】:
在我的情况下,这是一个 DNS 问题。 license.cmadsystems.com 解析到错误的 IP 地址。
【讨论】:
【参考方案2】:echo file_get_contents(
"http://license.cmadsystems.com?lic=P9xP1o7USRLkS591cFzBbLSmI9ZTtvR7xgfr86dtYiCZuhy"
);
返回
"status":200,
"status_message":"Licensed",
"data":
"Lic_End":null,
"Lic_Device":0,
"Lic_MOH":0,
"Lic_Info":null
【讨论】:
这不应该是一个答案,因为它已经在 cmets 中说明了十几次;)以上是关于PHP CURL GET 403 禁止的主要内容,如果未能解决你的问题,请参考以下文章