i have a strange problem bugging me for some time now and i am unable to resolve it. For testing purposes i create a URL with a parameter which is used to get a result from the database. It works fine most of the time, but it seems to struggle with special characters, like the "ß".
Here is an example URL where the user is urlencoded:
https://www.testurl.com/login.php?user=bu%DFmann (bu%DFmann = bußmann)
And this is a part of my php script:
$user = new User;
$loginOrEmail = $this->_helper->get_request_value("user", array("get"));
if ($user->check_user_is_valid($loginOrEmail)) {
.........
This is the check_user_is_valid method:
$sql = "SELECT * FROM user WHERE (email='" . mysql_real_escape_string($loginOrEmail) . "' OR login='" . mysql_real_escape_string($loginOrEmail) . "') AND activated = 'yes'";
$result = $database->query($sql);
if (mysql_num_rows($result) < 1) {
return false;
}
return true;
Now this seems to return false for the url above. If i print the query (with print_r or var_dump) the query looks fine:
SELECT * FROM user WHERE (email='bußmann' OR login='bußmann') AND activated = 'yes'
In fact. If i copy and paste this query to phpMyAdmin and execute it, it yields the row i was expecting. What is going on here? Where is the problem? I am pretty sure it has something to do with wrong encoding or something, because it works for all other names.
I already have mysql_set_charset('utf-8', $connection); after i connect to the database.
Please NOTE: I am aware that this is neither secure nor the best way to go. It is just for testing purposes.
mysql_set_charset('utf8', $connection);and notmysql_set_charset('utf-8', $connection);remove the hyphen and try it again.$user = new User;try$database->query('set name utf8');or place it before$result = $database->query($sql);see if that makes it kick in.<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />$con->set_charset("utf8");$conbeing my DB connection variable. Which is placed "before" the querySELECT * FROM user...