2

I've got a problem with CodeIgniter filtering out POST variables containing characters with accents.

Here's my HTML page:

<!DOCTYPE html>
<head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /></head>
<body>    
    <form action="/test" method="post" accept-charset="utf-8">
        <input type="text" name="name" value=""  />
        <input type="submit" name="submit" value="Submit"  />    
<form>    
</body>
</html>

Here's the index function of my '/test' CodeIgniter controller:

public function index {
    echo '<pre>';
    print_r($_POST);
    die();
}

...With the name entered as to 'my name' I get this:

Array
(
    [name] => my name
    [submit] => Submit
)

...But with the name entered as 'my namé', the variable gets passed as empty:

Array
(
    [name] => 
    [submit] => Submit
)

If I post the same form to a standalone PHP script it works fine. I can't see anything obvious in the config that's causing this. Can anyone help?

Ade
  • 2,961
  • 4
  • 30
  • 47
  • Did you check this question?http://stackoverflow.com/questions/5784207/post-empty-on-utf-8-characters – Can Vural Oct 22 '11 at 22:12
  • 1
    Further to this, according to: http://codeigniter.com/user_guide/libraries/input.html """ The security filtering function is called automatically when a new controller is invoked. It [...] Filters the POST/COOKIE array keys, permitting only alpha-numeric (and a few other) characters.""" – So how do I change this? – Ade Oct 22 '11 at 22:13
  • 1
    OK... Thanks for the link @Kobayakawa . The problem is isolated to MAMP running PHP 5.3.X. There is no such problem on my CentOS / Apache web server running PHP 5.3.8. Switching MAMP to PHP 5.2 fixes it (but isn't great because I'm running 5.3 in production) – Ade Oct 22 '11 at 23:03
  • @Ade: Check the PHP configuration if there are differences, especially with mb_string default configuration/encoding, the PCRE version. And ensure you have `xss_clean` disabled on both sites. – hakre Oct 22 '11 at 23:09
  • @hakre In php.ini in both environments, all references to mbstring are commented out. My application code locally on MAMP is identical to the code running remotely on LAMP, except for an environment variable. – Ade Oct 22 '11 at 23:16

2 Answers2

2

In config.php, change this -

/*
|--------------------------------------------------------------------------
| Default Character Set
|--------------------------------------------------------------------------
|
| This determines which character set is used by default in various methods
| that require a character set to be provided.
|
| See http://php.net/htmlspecialchars for a list of supported charsets.
|
*/
$config['charset'] = 'UTF-8';

to something else... basically what happens is if it's set to UTF-8 CI by default runs everything through a filter to check/convert if the app is expecting UTF-8, and the implementation of iconv() is the culprit... see this thread for more info https://github.com/EllisLab/CodeIgniter/issues/261

tgriesser
  • 2,808
  • 1
  • 22
  • 22
-1

It was a MAMP-specific issue, and effectively a duplicate of this question, which provides solutions: $_POST empty on utf-8 characters

Community
  • 1
  • 1
Ade
  • 2,961
  • 4
  • 30
  • 47