dourui9570 2013-07-03 13:23
浏览 42

变音问题(UTF-8)仅在首页加载时出现

I have a php/mysql-application on a plesk-server with Apache and nginx. I have the strange problem that only when the browser is opened and the website is accessed for the first time in that browser-session, Umlaute (special characters) like the german ä ö ü are displayed as "?". As soon as I refresh the site, it won't happen again until I close and re-open the browser.

Everything from DB over PHP to HTML is UTF-8 encoded.

Any hints what I should look for?

I noticed that when deleting the cookies, closing and opening the browser, it does NOT happen.

I noticed the problems only happen with content coming from the (entirely UTF-8-encoded) MySql-DB and only when I'm logged in... very strange!

Solution

Ok, I'm not the person that silently goes away when I was just too dump to find my fault! So, hopefully my error will help someone else in the future:

I had a PDO-connection that only happens when a user was logged in, but his session timed out. This query logs the user in based on a cookie. On that SQL-connection, I had only:

$db = new PDO("mysql:host=$dbhost;dbname=$dbname", $dbuser, $dbpass);

instead of

$db = new PDO("mysql:host=$dbhost;dbname=$dbname", $dbuser, $dbpass, array(PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES utf8"));

As it seems, this was the whole error!

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥500 火焰左右视图、视差(基于双目相机)
    • ¥100 set_link_state
    • ¥15 虚幻5 UE美术毛发渲染
    • ¥15 CVRP 图论 物流运输优化
    • ¥15 Tableau online 嵌入ppt失败
    • ¥100 支付宝网页转账系统不识别账号
    • ¥15 基于单片机的靶位控制系统
    • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
    • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
    • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本