I have a question. I just recently switched from iso-8859-1 to utf-8, both in my SQL-database and generally throughout all my PHP-files. All my PHP-script does is GET whatever was put in a form (X), and search for it in the SQL-database, and present the data, while also displaying the message "X returned Y results."
Now I have a question to ask regarding the use of mb_check_encoding
. I read the following in this thread:
Unfortunately, you should verify every received string as being valid UTF-8 before you try to store it or use it anywhere. PHP's mb_check_encoding() does the trick, but you have to use it religiously. There's really no way around this, as malicious clients can submit data in whatever encoding they want, and I haven't found a trick to get PHP to do this for you reliably.
As you can tell, I'm quite worried. I have done the following:
- Switched my SQL-database to utf8mb4.
- Used
$mysqli->set_charset('utf8mb4');
for the connection between the database and the PHP-file. - Set my charset in my HTML/PHP-file through
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
. - Saved all my files in UTF-8 (no BOM).
- Used
htmlspecialchars($_GET['name'], ENT_COMPAT | ENT_HTML401, 'UTF-8')
for the "X returned Y results."-message.
My question is this: Should I still use the mb_check_encoding
, even if I have done all of the above? And how would I check if I'm vulnerable to this "malicious" attack?