UTF-8在托管A上有效,但在托管B上无效,可能是什么原因引起的? [英] UTF-8 works on hosting A but not on hosting B, what could be causing it?

查看:69
本文介绍了UTF-8在托管A上有效,但在托管B上无效,可能是什么原因引起的?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我与2个不同的提供程序有托管计划,在提供程序A上,我的网站正常运行,没有出现任何问题,但是无论我做什么,在提供程序B上,UTF-8都不起作用.

两个托管网站的网站在各个方面都完全相同,因此我们唯一的区别是服务器.

如果我在记事本上简单创建一个具有以下内容的文件,另存为UTF-8 enc:

<?php
header('content-type: text/html; charset: utf-8'); 
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
</head>
<body>
<?
    $var = "áéíóí";
    echo $var;
?>
<body>
<html> 

在托管A上工作正常,但在托管B上无法显示字符.

我已经检查了两个php.ini文件,并且都具有相同的信息.

我还能尝试,更改或尝试使UTF-8在托管B上工作吗?

据我所知,似乎整个服务器端都缺少一些配置,否则为什么同一个站点可以在不显示单个问题的情况下在托管A上正常工作?

CURL响应托管B:

root@server:~# curl -v http://painel.xxxxxx.com/test.php
* About to connect() to painel.xxxxxx.com port 80 (#0)
*   Trying 10.0.0.2... connected
* Connected to painel.xxxxxx.com (10.0.0.2) port 80 (#0)
> GET /test.php HTTP/1.1
> User-Agent: curl/7.20.1 (i686-pc-linux-gnu) libcurl/7.20.1 OpenSSL/0.9.8n zlib/1.2.5 libidn/1.5
> Host: painel.xxxxxx.com
> Accept: */*
>
< HTTP/1.1 200 OK
< Date: Thu, 15 Sep 2011 11:55:33 GMT
< Server: Apache/2.2.15 (Unix) mod_ssl/2.2.15 OpenSSL/0.9.8n DAV/2 mod_python/3.3.1 Python/2.6.4 PHP/5.3.6 SVN/1.6.11 mod_fastcgi/2.4.6
< X-Powered-By: PHP/5.3.6
< Transfer-Encoding: chunked
< Content-Type: text/html; charset=utf-8
<
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
</head>
<body>
áéíóíaed<body>
* Connection #0 to host painel.xxxxxx.com left intact
* Closing connection #0
<html>

从我的计算机托管B的FireBug响应:

HTTP/1.1 200 OK
Date: Thu, 15 Sep 2011 12:06:21 GMT
Server: Apache/2.2.15 (Unix) mod_ssl/2.2.15 OpenSSL/0.9.8n DAV/2 mod_python/3.3.1 Python/2.6.4 PHP/5.3.6 SVN/1.6.11 mod_fastcgi/2.4.6
X-Powered-By: PHP/5.3.6
Keep-Alive: timeout=5, max=100
Connection: Keep-Alive
Transfer-Encoding: chunked
Content-Type: text/html; charset=utf-8

Host    painel.xxxxxxx.com
User-Agent  Mozilla/5.0 (Windows NT 5.1; rv:6.0.2) Gecko/20100101 Firefox/6.0.2
Accept  text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language pt-br,pt;q=0.8,en-us;q=0.5,en;q=0.3
Accept-Encoding gzip, deflate
Accept-Charset  ISO-8859-1,utf-8;q=0.7,*;q=0.7
Connection  keep-alive
Cookie  
Cache-Control   max-age=0

到目前为止已尝试:

  • 将语言环境从操作系统更改为en_US.UTF8
  • 更改了默认的apache字符集
  • 在php.ini上将charest设置为utf-8
  • 文件保存在UTF8上
  • 同一文件在两个托管计划中均经过测试,并且仅在托管A上有效.
  • 代码mb_internal_encoding("UTF-8");
  • 的第一行
  • 在代码setlocale(LC_CTYPE, 'C');
  • 的第一行
  • 上面两个一起
  • header('content-type: text/html; charset: utf-8');header('content-type: text/html; charset=utf-8');

解决方案

将以下行添加到php.ini文件并重新启动httpd服务就可以了:

mbstring.internal_encoding=utf-8

I have hosting plans with 2 different providers, on provider A my website work without a single issue but on provider B no matter what I do the UTF-8 never works.

The website in both hosting are exact the same in every aspect so the only difference we have here is the server.

If I simple create a file with the below content on notepad saving as UTF-8 enc:

<?php
header('content-type: text/html; charset: utf-8'); 
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
</head>
<body>
<?
    $var = "áéíóí";
    echo $var;
?>
<body>
<html> 

It works fine on hosting A but fails to show the characters on hosting B.

I have checked both php.ini files and both have the same information.

What else could I try, change or attempt to get UTF-8 working on hosting B ?

From what I can tell it seems entirelly server side issue some configuration missing or so otherwise why the same site would work on hosting A without demonstrating a single issue ?

CURL response hosting B:

root@server:~# curl -v http://painel.xxxxxx.com/test.php
* About to connect() to painel.xxxxxx.com port 80 (#0)
*   Trying 10.0.0.2... connected
* Connected to painel.xxxxxx.com (10.0.0.2) port 80 (#0)
> GET /test.php HTTP/1.1
> User-Agent: curl/7.20.1 (i686-pc-linux-gnu) libcurl/7.20.1 OpenSSL/0.9.8n zlib/1.2.5 libidn/1.5
> Host: painel.xxxxxx.com
> Accept: */*
>
< HTTP/1.1 200 OK
< Date: Thu, 15 Sep 2011 11:55:33 GMT
< Server: Apache/2.2.15 (Unix) mod_ssl/2.2.15 OpenSSL/0.9.8n DAV/2 mod_python/3.3.1 Python/2.6.4 PHP/5.3.6 SVN/1.6.11 mod_fastcgi/2.4.6
< X-Powered-By: PHP/5.3.6
< Transfer-Encoding: chunked
< Content-Type: text/html; charset=utf-8
<
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
</head>
<body>
áéíóíaed<body>
* Connection #0 to host painel.xxxxxx.com left intact
* Closing connection #0
<html>

FireBug response hosting B from my computer:

HTTP/1.1 200 OK
Date: Thu, 15 Sep 2011 12:06:21 GMT
Server: Apache/2.2.15 (Unix) mod_ssl/2.2.15 OpenSSL/0.9.8n DAV/2 mod_python/3.3.1 Python/2.6.4 PHP/5.3.6 SVN/1.6.11 mod_fastcgi/2.4.6
X-Powered-By: PHP/5.3.6
Keep-Alive: timeout=5, max=100
Connection: Keep-Alive
Transfer-Encoding: chunked
Content-Type: text/html; charset=utf-8

Host    painel.xxxxxxx.com
User-Agent  Mozilla/5.0 (Windows NT 5.1; rv:6.0.2) Gecko/20100101 Firefox/6.0.2
Accept  text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language pt-br,pt;q=0.8,en-us;q=0.5,en;q=0.3
Accept-Encoding gzip, deflate
Accept-Charset  ISO-8859-1,utf-8;q=0.7,*;q=0.7
Connection  keep-alive
Cookie  
Cache-Control   max-age=0

Tried so far:

  • changed hte locale from the OS to en_US.UTF8
  • changed the default charset on apache
  • set the charest to utf-8 on php.ini
  • files are save on UTF8
  • the same file is tested on both hosting plans and only works at hosting A.
  • at the first line of the code mb_internal_encoding("UTF-8");
  • at the first line of the code setlocale(LC_CTYPE, 'C');
  • the 2 above together
  • header('content-type: text/html; charset: utf-8'); and header('content-type: text/html; charset=utf-8');

解决方案

Adding the follow line to the php.ini file and rebooting the httpd service did the trick:

mbstring.internal_encoding=utf-8

这篇关于UTF-8在托管A上有效,但在托管B上无效,可能是什么原因引起的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆