php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #63094 Different behavior of $_POST data when setting mbstring.internal_encoding on ru
Submitted: 2012-09-15 12:42 UTC Modified: 2013-06-29 05:31 UTC
Votes:4
Avg. Score:4.2 ± 0.8
Reproduced:4 of 4 (100.0%)
Same Version:2 (50.0%)
Same OS:2 (50.0%)
From: seven at nivas dot hr Assigned:
Status: Not a bug Package: mbstring related
PHP Version: 5.4.7 OS: windows & unix
Private report: No CVE-ID: None
 [2012-09-15 12:42 UTC] seven at nivas dot hr
Description:
------------
I am unaware if this is a bug or feature, but it’s strange. It should be fixed or documented somewhere. 

I’ve run into this in process of debugging a problem I was having with old code running on php 5.4 and php 5.4.7 which caused all utf8 form data to be submitted in wrong encoding. Instead of “[šđčćž]“ I would get “[šđčćž]“. After a while I've found out that because of the utf8 changes implemented into php 5.4.x mbstring.http_input=auto should be set to “pass”.
my php.ini has default_charset = "UTF-8" and my form is on utf8 html page and <form tag has accept-charset="utf-8".

Imagine having this in .htaccess file:
php_value mbstring.encoding_translation	 1
php_value mbstring.internal_encoding	 UTF-8
php_value mbstring.http_input		 auto

and this in php:
echo $_POST['test']; // outputs [šđčćž]

php ini_get sees this, so all settings are applied ok:
mbstring.internal_encoding:UTF-8
mbstring.encoding_translation:1
mbstring.http_input:auto

The utf8 form data problem occurs.

Now, imagine having only this in .htaccess (since encoding_translation is PHP_INI_PERDIR setting and can’t be set from runtime):
php_value mbstring.encoding_translation	 1

and this in  php:
mb_internal_encoding ('UTF-8');
mb_http_input('auto');
echo $_POST['test']; // outputs [šđčćž]

php ini_get sees this, so all settings are applied ok:
mbstring.internal_encoding:UTF-8
mbstring.encoding_translation:1
mbstring.http_input:auto

No utf8 data form submission problem.


mbstring.internal_encoding is PHP_INI_ALL setting, however, it does not behave the same if set from .htaccess or .php. It seems to me that setting it from .php does not make any change in how mbstring.http_input will process form data.



Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2013-06-29 05:31 UTC] yohgaki@php.net
-Status: Open +Status: Not a bug
 [2013-06-29 05:31 UTC] yohgaki@php.net
Input encoding translation is used when browser are wrongly implemented. 
Currently used browsers send the charset as the page. So translation is not 
needed.

Exception is mobile or old devices. If you have to use this feature, change 
mbstring.detect_order and 'always supply enough data to detect encoding 
correctly'
 [2013-08-21 07:38 UTC] tomas dot glabasna at seznam dot cz
I tested with the new Firefox and Chrome

PHP 5.4.18 - Problem
PHP 5.3.3 and 5.2.14 is OK

var_dump(mb_detect_order()); // array(2) { [0]=> string(5) "ASCII" [1]=> string(5) "UTF-8" }
 
PHP Copyright © 2001-2022 The PHP Group
All rights reserved.
Last updated: Sat Dec 03 01:05:56 2022 UTC