Php 标题响应“;403禁止;使用cURL,file_get_contents()和fopen()

Php 标题响应“;403禁止;使用cURL,file_get_contents()和fopen(),php,Php,我希望你能帮助我。 该网站目前处于在线状态,我可以很好地访问它,我似乎不明白为什么这不起作用 file\u get\u contents()和fopen()返回如下错误: PHP警告:文件获取内容(http://www.hackforums.net):无法打开流:HTTP请求失败!HTTP/1.1 403第29行的/host/Users/Phizo/Desktop/stapper.php中禁止使用 现在我刚开始卷曲,因为我想试着绕过403,也没有运气 $handle=curl_init();

我希望你能帮助我。 该网站目前处于在线状态,我可以很好地访问它,我似乎不明白为什么这不起作用

file\u get\u contents()
fopen()
返回如下错误:

PHP警告:文件获取内容(http://www.hackforums.net):无法打开流:HTTP请求失败!HTTP/1.1 403第29行的/host/Users/Phizo/Desktop/stapper.php中禁止使用
现在我刚开始卷曲,因为我想试着绕过403,也没有运气

$handle=curl_init();
$file=fopen('source.txt','w');
curl_setopt($handle,CURLOPT_URL,'http://www.hackforums.net/');
curl_setopt($handle,CURLOPT_CUSTOMREQUEST,'GET');
curl_setopt($handle,CURLOPT_HEADER,true);
curl_setopt($handle,CURLOPT_AUTOREFERER,true);
curl_setopt($handle,CURLOPT_USERAGENT,'Mozilla/5.0(X11;Ubuntu;Linux x86_64;rv:13.0)Gecko/20100101 Firefox/13.0.1');
curl_setopt($handle,CURLOPT_FOLLOWLOCATION,true);
curl_setopt($handle,CURLOPT_FILE,$FILE);
curl_exec($handle);
打印(curl_getinfo($handle));
卷曲关闭($handle);
fclose($文件);
输出以下错误:

致命错误:第29行的D:\Hosting\6514439\html\zeonsgloads\admin\press\uploads\stapper.php中超过了30秒的最大执行时间

此代码适用于我,您无需执行自定义请求即可实现所需

$handle = curl_init();

curl_setopt($handle, CURLOPT_URL, 'http://www.hackforums.net/');
curl_setopt($handle, CURLOPT_HEADER, true);
curl_setopt($handle, CURLOPT_USERAGENT, 'Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:13.0) Gecko/20100101 Firefox/13.0.1');
curl_setopt($handle, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($handle, CURLOPT_RETURNTRANSFER, 1);

$result = curl_exec($handle);

var_dump($result);

curl_close($handle);
您得到403的原因可能是因为fopen传递的用户代理。如果从curl请求中删除用户代理,您还将得到403错误

我添加了curl选项
CURLOPT\u RETURNTRANSFER
,因此当您调用
curl\u exec()
时,它会以字符串形式返回响应


希望能有所帮助。

这段代码对我很有用,您不需要执行自定义请求即可实现所需的功能

$handle = curl_init();

curl_setopt($handle, CURLOPT_URL, 'http://www.hackforums.net/');
curl_setopt($handle, CURLOPT_HEADER, true);
curl_setopt($handle, CURLOPT_USERAGENT, 'Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:13.0) Gecko/20100101 Firefox/13.0.1');
curl_setopt($handle, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($handle, CURLOPT_RETURNTRANSFER, 1);

$result = curl_exec($handle);

var_dump($result);

curl_close($handle);
您得到403的原因可能是因为fopen传递的用户代理。如果从curl请求中删除用户代理,您还将得到403错误

我添加了curl选项
CURLOPT\u RETURNTRANSFER
,因此当您调用
curl\u exec()
时,它会以字符串形式返回响应


希望这能有所帮助。

这对我来说不起作用,但是我使用stream\u context\u create()解决了这个问题。似乎fopen正在传递用户代理“PHP”,就像您所说的那样。所以你帮我想出了一个方法,谢谢:)。这对我来说不起作用,但是我设法用stream_context_create()解决了这个问题。似乎fopen正在传递用户代理“PHP”,就像您所说的那样。所以你帮我想出了一个办法,谢谢:)。