Answer the question
In order to leave comments, you need to log in
PHP. How to implement authorization in a bot?
Good afternoon, fellow experts)
We need a fresh look at the script)
In short, there is a chat bot, simple. PHP processes the responses, JS outputs all this to HTML.
There is a csv file for the script. Which is processed in PHP. In the first column, what the user says to the bot, and in the second, what the bot replies.
I wanted to expand the functionality of the bot, so to speak.
I want to somehow implement authorization from the bot. That is, I write a secret phrase, he enters a separate mode, asks for a password, we write him a password, he says OK and does what we specify in this block. And all this decision lasts until we enter the EXIT stop phrase.
Are there options to do this in the body of one script? I tried to make a bunch of if and do and while conditions but got confused..
PHP:
<?php
$responses=array();
$handle = fopen('php://memory', 'w+');
fwrite($handle, iconv('CP1251', 'UTF-8', file_get_contents('base/base.csv')));
rewind($handle);
while (($row = fgetcsv($handle, 1000, ';')) !== false)
{
$d=$row[0];
$b=$row[1];
$responses["$d"] = $b;
}
fclose($handle);
$q = $_GET["q"];
$response = "";
if ($q != "") {
# code...
$q = strtolower($q);
foreach ($responses as $r => $value) {
# code...
$r = strtolower($r);
if ($r== $q) {
//if (strpos($r, $q) !== false) {
# code...
$response = $value;
if (strpos($r, $q)==1) {
$response = "Я не понимаю!";
$noresponse = "Я не понимаю!";
}
}
}
}
$noresponse = "Я не понимаю!";
echo $response === "" ? $noresponse : $response;
//var_dump($handle);
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question