Browse code

utf8 slip (to be tested)

devnewton authored on 05/05/2017 10:05:31
Showing 1 changed files
... ...
@@ -3,10 +3,19 @@
3 3
 include_once 'common.php';
4 4
 
5 5
 $lastId = filter_input(INPUT_POST, 'lastId', FILTER_VALIDATE_INT, array('options' => array('default' => 0)));
6
-$message = substr(filter_input(INPUT_POST, 'message', FILTER_UNSAFE_RAW, FILTER_FLAG_STRIP_LOW), 0, TAAB_MAX_POST_LENGTH);
7
-$login = trim(substr(filter_input(INPUT_POST, 'login', FILTER_SANITIZE_EMAIL), 0, TAAB_MAX_LOGIN_LENGTH));
8
-$info = trim(substr(filter_input(INPUT_SERVER, 'HTTP_USER_AGENT', FILTER_SANITIZE_EMAIL), 0, TAAB_MAX_INFO_LENGTH));
9
-if (strlen($login) === 0 && strlen($info) === 0) {
6
+$message = mb_substr(filter_input(INPUT_POST, 'message', FILTER_UNSAFE_RAW, FILTER_FLAG_STRIP_LOW), 0, TAAB_MAX_POST_LENGTH);
7
+$login = trim(mb_substr(filter_input(INPUT_POST, 'login', FILTER_SANITIZE_EMAIL), 0, TAAB_MAX_LOGIN_LENGTH));
8
+$info = trim(mb_substr(filter_input(INPUT_SERVER, 'HTTP_USER_AGENT', FILTER_SANITIZE_EMAIL), 0, TAAB_MAX_INFO_LENGTH));
9
+
10
+if(!mb_detect_encoding($login, 'UTF-8', true)) {
11
+    $login = "relou";
12
+}
13
+
14
+if(!mb_detect_encoding($info, 'UTF-8', true)) {
15
+    $info = "relou";
16
+}
17
+
18
+if (mb_strlen($login) === 0 && mb_strlen($info) === 0) {
10 19
     $info = "coward";
11 20
 }
12 21
 
... ...
@@ -18,7 +27,7 @@ while (($post = fgetcsv($file, TAAB_MAX_BACKEND_LINE_LENGTH, "\t")) !== FALSE) {
18 27
     $newPosts[] = $post;
19 28
     $newPostId = max($newPostId, $post[0]);
20 29
 }
21
-if (strlen(trim($message)) > 0) {
30
+if (mb_strlen(trim($message)) > 0 && mb_detect_encoding($message, 'UTF-8', true)) {
22 31
     ++$newPostId;
23 32
     $dateTime = date_create("now", timezone_open("Europe/Paris"));
24 33
     $time = date_format($dateTime, 'YmdHis');