There is such a code, how to implement a function (not changing the code a lot) that will compare the ID in the user_id.txt list and, depending on True or False (whether or not this ID is in the list), will send the corresponding request ...
If the first user writes, it works as it should:
P -> Subscription
About -> Thank you for subscribing ...
P -> Subscription
About -> I can not subscribe you ...
But when the second user writes according to this scheme, he does not reach the moment “I can't ...”, although the user ID is in the list ... I am new to PHP, I hope for your help.
$file_join = fopen("user_id.txt", "r"); //Открываем файл //Поиск ранее вписанных ID $buffer_join = fread($file_join, filesize("user_id.txt")); //Читаем файл fclose($file); //закрываем файл if($user_msg == "Подписаться"){ if($user_id == "$buffer_join"){ $v->msgSend("Я не могу тебя подписаться, ты уже подписан на рассылку!", $user_id, $access_token); } else { $v->msgSend("Спасибо что подписался на рассылку. Что бы отписаться от рассылки отправьте мне: «Отписка».", $user_id, $access_token); $file = fopen("user_id.txt", "r"); //Открываем файл //Поиск ранее вписанных ID $buffer = fread($file, filesize("user_id.txt")); //Читаем файл fclose($file); //закрываем файл if (substr_count($buffer, "$user_id")>0){ //Ищем ID пользователя // Сходство найдено } else { //Сходство не найдено $fp = fopen("user_id.txt", "a"); // Открываем файл в режиме записи $mytext = "$user_id;\n"; // Исходная строка $test = fwrite($fp, $mytext); // Запись в файл fclose($fp); //Закрытие файла }}} The list of IDs in the user_id.txt file looks like this.
29674938; 14143596;