【问题标题】:get_headers returning error on new serverget_headers 在新服务器上返回错误
【发布时间】:2014-10-02 08:29:23
【问题描述】:

我在我的一个旧网站上创建了一个图像处理函数,该函数在一个页面上运行,该页面接收图像的完整 URL 作为 get 变量。该函数的一部分使用 get_headers 来获取请求文件的内容类型。

虽然这在我的旧服务器上有效,但我最近搬到了新服务器上,我记得这个页面遇到了各种各样的问题,但我认为这是 GD 库更多的服务器端。

我在运行 php 5.4.X 和 WHm cPanel 的专用服务器上运行该站点,因此我可以根据需要完全更改和安装东西。

麻烦的代码

<?php

//Get the file and set the headers to the file type
$file           = $_GET['file'];
$headers        = get_headers($file, 1);
header('Content-Type: '.$headers['Content-Type']);

页面响应

Warning: get_headers(): php_network_getaddresses: getaddrinfo failed: Name or service not known in [Removed url] on line 5

Warning: get_headers([Removed url]): failed to open stream: php_network_getaddresses: getaddrinfo failed: Name or service not known in [Removed url] on line 5

Warning: Cannot modify header information - headers already sent by (output started at [Removed url]:5) in [Removed url] on line 6

我更改服务器端的唯一一件事是在 WHM 中将 allow_url_fopen 设置为打开,我尝试过的所有其他操作在它不起作用后都已重置。

【问题讨论】:

  • 您最近多久移动过服务器?如果域尚未传播,则可能是 DNS 问题。

标签: php apache cpanel whm


【解决方案1】:

如果地址正确并且您最近更改了名称,这似乎是 DNS 解析问题 域的服务器,或者例如 A 记录,那么 DNS“传播”可能正在发生。您可以使用 google 的公共域名服务器更快地获得它,如下所示:

nano /etc/resolv.conf

然后设置你的域名服务器:

nameserver 8.8.8.8 
nameserver 8.8.4.4

【讨论】:

  • 写出了几乎完全相同的答案,但你打败了我:(虽然你没有打败我的评论!
  • 您也可以通过将主机添加到 /etc/hosts 来临时解决问题(请在 DNS 更改开始后将其删除)。
猜你喜欢
  • 2014-06-17
  • 1970-01-01
  • 1970-01-01
  • 2019-10-16
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多