Question

I added this LoginLdap plugin to piwik and while it's running perfectly on other machines without any problems, on my debian box it doesn't.

The connection to the LDAP server works, but as soon as I try to login via an LDAP user I get the error:

Warning: json_encode(): Invalid UTF-8 sequence in argument in /var/www/plugins/LoginLdap/GigatecLdap.php on line 44

I did a var_dump() on $result in line 43 and saw that OpenLDAP seems to return some weird characters from AD, that json_encode just can't handle.

You can see the sources here.

Was it helpful?

Solution

You need to find out what character set the entries are being stored in on the LDAP server. You might have some luck using mb_detect_encoding for this. Hopefully this will return the name of the character set, in which case you can do the following:

$utf8String = iconv(mb_detect_encoding($string), 'utf8', $string);

In the case that mb_detect_encoding returns false — i.e. the encoding is unknown — you can have a go at working it out yourself (tedious, but rewarding). Find a string containing a known character which is causing problems. Work out the byte representation of the string with the following:

$bytes = unpack('H*', $string);

Then look up your character on FileFormat and look at the charset/codepage support for that character, matching up the bytes with the corresponding bytes from above. You should then be able to use that character set name as the first parameter of iconv.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top