T
T
TechNOIR2018-01-28 17:12:05
PHP
TechNOIR, 2018-01-28 17:12:05

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:

spoiler
<?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);


q - what we enter into the chat.
Any ideas or parting words comrades?) Thank you)

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
marataziat, 2018-02-09
@marataziat

And what about Javascript?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question