user3438083
user3438083

Reputation: 79

file_get_contents not working on my server

I have created two files, one on my wamp server (localhost), and one on my ovh.com private space. Both files contains only this content :

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');

On my server, there is some wrong characters, like â, þ or ¬, etc ...

How it can happends, and how can I resolve this ?

Edit: It's not about files ! It's about servers, cause files are exactly the same ! You can check the good one here : http://www.dietadom.fr/test.php, and the bad one here : http://82.124.50.144/test.php

headers from requests to both those scripts:

Working:

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

Not Working:

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

Upvotes: 0

Views: 1597

Answers (1)

DorianFM
DorianFM

Reputation: 4483

Most likely the default character encoding header provided by your two servers is different. You can fix this by changing the server configurations to make sure they both have the default. Or you can modify your script to over-ride this, adding a content encoding header will make this consistent.

If you modify your PHP file for UTF-8 plain test content the line would be

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

Your source URL is responding with:

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

retrieved using

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

hence how I know it's UTF-8 encoded.

EDIT

Having checked against your server I can see the header for an error page of:

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

The last line showing me the default charecter encoding is iso-8859-1, which means that the utf-8 data from your source is being transmitted with the wrong encoding. Adding the correct header line to your script should fix the issue.

You could change your apache server configuration by adding AddDefaultCharset UTF-8 as well.

I'm sure that your issue is with character encoding, so you should look into that.

Upvotes: 2

Related Questions