тестбот - PHP Online

Form of PHP Sandbox

Enter Your PHP code here for testing/debugging in the Online PHP Sandbox. As in the usual PHP files, you can also add HTML, but do not forget to add the tag <?php in the places where the PHP script should be executed.



Your result can be seen below.

Result of php executing





Full code of тестбот.php

  1. /**
  2. *   daun bot
  3. *   04.07.2022
  4. */
  5. header('Content-Type: text/html; charset=utf-8'); 
  6.  
  7. $site_dir = dirname(dirname(__FILE__)).'/'; 
  8. $bot_token = '5500279656:AAGMt5Hi424BcDUEtVydkKA43s0juM9bwM4'; 
  9. $data = file_get_contents('php://input');
  10. $data = json_decode($data, true); 
  11.  
  12. file_put_contents(__DIR__ . '/message.txt', print_r($data, true));
  13.  
  14.  
  15. if (!empty($data['message']['text'])) {
  16.     $chat_id = $data['message']['from']['id'];
  17.     $user_name = $data['message']['from']['username'];
  18.     $first_name = $data['message']['from']['first_name'];
  19.     $last_name = $data['message']['from']['last_name'];
  20.     $text = trim($data['message']['text']);
  21.     $text_array = explode(" ", $text);
  22.     
  23.     if ($text == '/help') {
  24.         $text_return = "Шалом, хуйло, всё чо умею: 
  25. /help - для даунов
  26. /roll - кости
  27. /token - монетка
  28.  
  29. ";
  30.         message_to_telegram($bot_token, $chat_id, $text_return);
  31.     }
  32.     
  33.     if ($text == '/roll') 
  34.     then 
  35.  
  36.        { $text_return = "гля шо выкинул
  37.        <?php
  38.     echo rand(1, 6);
  39.     ?>
  40.  и 
  41.  <?php
  42.     echo rand(1, 6);
  43.     ?>
  44.     "; 
  45.  
  46.         message_to_telegram($bot_token, $chat_id, $text_return);
  47.     }
  48. if ($text == '/token') 
  49.     then
  50.     <?php
  51.     echo rand(0, 1);
  52.     ?>
  53.     
  54. if rand = 0 then 
  55.  
  56.        { $text_return = "еба орёл
  57.        
  58.     "; 
  59.  
  60.         message_to_telegram($bot_token, $chat_id, $text_return);
  61.     }
  62. if rand = 1 then
  63.  { $text_return = "еба решка
  64.        
  65.     "; 
  66.  
  67.         message_to_telegram($bot_token, $chat_id, $text_return);
  68.     }
  69.  
  70.  
  71. function message_to_telegram($bot_token, $chat_id, $text, $reply_markup = '')
  72. {
  73.     $ch = curl_init();
  74.     $ch_post = [
  75.         CURLOPT_URL => 'https://api.telegram.org/bot' . $bot_token . '/sendMessage',
  76.         CURLOPT_POST => TRUE,
  77.         CURLOPT_RETURNTRANSFER => TRUE,
  78.         CURLOPT_TIMEOUT => 10,
  79.         CURLOPT_POSTFIELDS => [
  80.             'chat_id' => $chat_id,
  81.             'parse_mode' => 'HTML',
  82.             'text' => $text,
  83.             'reply_markup' => $reply_markup,
  84.         ]
  85.     ];
  86.  
  87.     curl_setopt_array($ch, $ch_post);
  88.     curl_exec($ch);
  89. }
  90.  
File Description
  • тестбот
  • PHP Code
  • 04 Jul-2022
  • 2.07 Kb
You can Share it: