繁体   English   中英

file_get_contents在我的服务器上不起作用

[英]file_get_contents not working on my server

我创建了两个文件,一个在我的wamp服务器(localhost)上,另一个在我的ovh.com私有空间上。 这两个文件只包含以下内容:

echo $search = file_get_contents('https://prod.api.pvp.net/api/lol/euw/v1.3/game/by-summoner/19319907/recent?api_key=6fa73a35-6477-412d-97a6-b6739cb6cf1b');

在我的服务器上,有一些错误的字符,如â,þ或¬等...

它是如何发生的,我该如何解决这个问题?

编辑:这不是关于文件! 这是关于服务器,原因文件是完全一样的! 你可以在这里检查好的: http//www.dietadom.fr/test.php ,这里有一个坏的: httphttp://82.124.50.144/test.php

从请求到这两个脚本的标头:

工作:

curl -I  http://www.dietadom.fr/test.php
HTTP/1.1 200 OK
Set-Cookie: clusterBAK=R1564861669; path=/; expires=Wed, 19-Mar-2014 16:38:43 GMT
Date: Wed, 19 Mar 2014 15:19:31 GMT
Content-Type: text/html
Connection: keep-alive
Set-Cookie: cluster=R1649376954; path=/; expires=Wed, 19-Mar-2014 16:32:22 GMT
Server: Apache
X-Powered-By: PHP/5.4.24
Pragma: no-cache
Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0
Vary: Accept-Encoding

不工作:

curl -I http://82.124.50.144/test.php
HTTP/1.1 200 OK
Date: Wed, 19 Mar 2014 15:19:48 GMT
Server: Apache/2.4.4 (Win64) OpenSSL/1.0.1d PHP/5.4.12
X-Powered-By: PHP/5.4.12
Content-Type: text/plain; charset: UTF-8

很可能两个服务器提供的默认字符编码头是不同的。 您可以通过更改服务器配置来确保它们都具有默认值来解决此问题。 或者您可以修改您的脚本以覆盖它,添加内容编码标题将使这一点保持一致。

如果您修改PHP文件以获得UTF-8普通测试内容,那么该行就是

header('Content-type: text/plain; charset=UTF-8');

您的源网址正在响应:

Content-Type: application/json; charset=UTF-8

检索使用

curl -I https://prod.api.pvp.net/api/lol/euw/v1.3/game/by-summoner/19319907/recent?api_key=6fa73a35-6477-412d-97a6-b6739cb6cf1b

因此我怎么知道它是UTF-8编码的。

编辑

检查过您的服务器后,我可以看到错误页面的标题:

curl -I http://82.124.50.144/404.html
HTTP/1.1 403 Forbidden
Date: Wed, 19 Mar 2014 17:24:17 GMT
Server: Apache/2.4.4 (Win64) OpenSSL/1.0.1d PHP/5.4.12
Content-Type: text/html; charset=iso-8859-1

显示默认字符编码的最后一行是iso-8859-1,这意味着来自源的utf-8数据使用错误的编码进行传输。 在脚本中添加正确的标题行可以解决问题。

您也可以通过添加AddDefaultCharset UTF-8来更改Apache服务器配置。

我确定你的问题是字符编码,所以你应该研究一下。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM