file_get_contents()突然不起作用 [英] file_get_contents() suddenly not working
问题描述
这是我的全部代码:
<html>
<body>
<form>
Playlist to Scrape: <input type="text" name="url" placeholder="Playlist URL">
<input type="submit">
</form>
<?php
if(isset($_GET['url'])){
$source = file_get_contents($_GET['url']);
$regex = '/<a href="(.*?)" class="gothere pl-button" title="/';
preg_match_all($regex,$source,$output);
echo "<textarea cols=100 rows=50>";
$fullUrl = array();
foreach($output[1] as $url){
array_push($fullUrl,"http://soundcloud.com".$url);
}
$final = implode(";",$fullUrl);
echo $final;
echo "</textarea>";
}else{
echo "borks";
}
?>
</body>
</html>
昨天,它运行良好. 代码应该要做的是: 获取Soundcloud URL,提取单个歌曲,然后将它们打印为song1; song2; song3
Yesterday, it worked fine. What the code should do is: Take a Soundcloud URL, extract the individual songs, and then print them like song1;song2;song3
再说一次,昨天这个工作还不错,自那以后我什么都没改变……
Again, this worked fine yesterday, and I haven't changed anything since, I think...
我试图注释掉其他代码,只是保持$ source = file_get_contents($ _ GET ['url']);并回显$ source,但它返回空白,这使我认为它是file_get_contents的问题.
I have tried to comment the other code out, and just keeping $source = file_get_contents($_GET['url']); and echoing $source, but it returned blank, which makes me think it is a problem with file_get_contents.
如果您对发生这种情况的原因有任何了解,不胜感激.谢谢!
If you have any idea on why this is happening, I would appreciate hearing it. Thanks!
推荐答案
可能发生的是,在file_get_contents
试图访问的服务器上安装了新的SSL证书.在我们的情况下,目标服务器在其域上从另一个供应商和另一个通配域安装了新的SSL证书.
What might have happened is that a new SSL certificate was installed on the server that file_get_contents
is trying to access. In our case, the target server had a new SSL certificate installed on its domain from another vendor and another wild-card domain.
稍微更改配置即可解决此问题.
Changing our config a little bit fixed the problem.
$opts = array(
'http' => array(
'method' => "GET",
'header' => "Content-Type: application/json\r\n".
"Accept: application/json\r\n",
'ignore_errors' => true
),
// VVVVV The extra config that fixed it
'ssl' => array(
'verify_peer' => false,
'verify_peer_name' => false,
)
// ^^^^^
);
$context = stream_context_create($opts);
$result = file_get_contents(THE_URL_WITH_A_CHANGED_CERTIFICATE, false, $context);
由于此答案,我找到了该解决方案.它甚至被否决了.
I found this solution thanks to this answer. It even was downvoted.
这肯定解释了file_get_contents
突然停止工作的事实.
This certainly explained the fact that file_get_contents
suddenly stops working.
这篇关于file_get_contents()突然不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!