file_get_contents在本地主机上有效,而不在共享主机上工作

问题描述 投票:0回答:1

这是一个简单的示例,此代码无需使用API​​即可获取所有Instagram用户的关注者计数。

$otherPage = 'nasa';
$response = file_get_contents("https://www.instagram.com/$otherPage/?__a=1");
if ($response !== false) {
    $data = json_decode($response, true);
    if ($data !== null) {
        $follows = $data['graphql']['user']['edge_follow']['count'];
        $followedBy = $data['graphql']['user']['edge_followed_by']['count'];
        echo $follows . ' and ' . $followedBy;
    }
}

此代码在我的本地主机和朋友的服务器上均有效,但在我的共享主机中却不起作用:(

file_get_contents功能运行良好,但仅适用于内部文件而不是在线链接。

任何人都知道为什么吗?

php instagram file-get-contents shared-hosting
1个回答
1
投票

这可能是由于托管服务提供商已禁用配置中的allow_url_fopen

将启用默认选项,这可能在您/您朋友的服务器上都是正确的,共享托管服务提供商通常会禁用此选项以及其他可能有害的东西/可能影响正在运行的其他网站同一主机。

要确认,请尝试获取该值,如果此值被禁用,则将无法从远程URI调用fopen

allow_url_fopen
© www.soinside.com 2019 - 2024. All rights reserved.