简体   繁体   English

Windows文件和PHP编码UTF-8

[英]Windows files and encoding UTF-8 with PHP

I have some problems with UTF-8 encoding in Windows Server. Windows Server中的UTF-8编码存在一些问题。

With the session var: $_SESSION['share'] = '\\\\server\\share\\almodóvar'; 使用会话var: $_SESSION['share'] = '\\\\server\\share\\almodóvar';

I read this one, the result is \\\\server\\share\\amod var and this works in a scandir with no problem. 我读了这本书,结果是\\\\server\\share\\amod var并且可以在scandir中正常工作。

The result of mb_detect_encoding($_SESSION['share']); mb_detect_encoding($_SESSION['share']); is UTF-8. 是UTF-8。

But, then if I refresh the page and I read the session var, the result is \\\\server\\share\\amod?var and the scandir doesn't work anymore. 但是,如果刷新页面并读取会话var,则结果为\\\\server\\share\\amod?var ,而scandir不再起作用。

The result of mb_detect_encoding($_SESSION['share']); mb_detect_encoding($_SESSION['share']); is ASCII. 是ASCII。

I already tried some php functions like utf8_encode() and others but this doesn't work. 我已经尝试了一些php函数,例如utf8_encode()和其他函数,但这不起作用。

Can you help me? 你能帮助我吗?

PS: I don't know if it can help, but I'm using Joomla CMS. PS:我不知道它是否可以帮助您,但是我正在使用Joomla CMS。 I don't think that'sthe problem. 我不认为这是问题。

Thank you in advance. 先感谢您。

The problem was that my Joomla CMS corrupts in my opinion the PHP SESSIONS and they have their own sessions who work very well. 问题是我认为我的Joomla CMS损坏了PHP SESSIONS,它们有自己的会话,它们可以很好地工作。

Into Joomla, they have JSESSIONS. 进入Joomla,他们有了JSESSIONS。 I let you their code for the sessions if someone is loocking for the same problem. 如果有人因同样的问题而讨厌我,我让他们为会议准备代码。


This is the Joomla Sessions (they avoid the most of the encoding and web server problems, etc): 这就是Joomla会话(它们避免了大多数编码和Web服务器问题等):

Solution: Replace session_start(); 解决方案:替换session_start(); in your external script with 在您的外部脚本中

define( '_JEXEC', 1 );
define( 'JPATH_BASE', realpath(dirname(__FILE__).'/../..' ));

require_once ( JPATH_BASE. '/includes/defines.php' );
require_once ( JPATH_BASE. '/includes/framework.php' );
$mainframe = JFactory::getApplication('site');
$mainframe->initialise();

Be sure to change JPATH_BASE to suit your directory structure. 确保更改JPATH_BASE以适合您的目录结构。

Replace the $_SESSION[ 'name' ] = "value"; 替换$ _SESSION ['name'] =“ value”; in your external script with 在您的外部脚本中

$session = JFactory::getSession();
$session->set('name', "value");

Now you can retrieve this session variable using: 现在,您可以使用以下方法检索此会话变量:

$session = JFactory::getSession();
echo $session->get('name');

I hope this is going to help anyone. 我希望这会帮助任何人。

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

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