<?php
error_reporting(E_ALL);
ini_set('display_errors', 1);

echo "<h1>Debug du système Telegram/Redirection</h1>";
echo "PHP Version : " . phpversion() . "<br><br>";

// 1. Tester les fonctions Telegram
echo "<h3>Test des fonctions nécessaires :</h3>";

// Test cURL (souvent utilisé pour Telegram)
if (function_exists('curl_init')) {
    echo "✅ cURL disponible<br>";
} else {
    echo "❌ cURL NON disponible - Installez php8.1-curl<br>";
}

// Test file_get_contents (alternative)
if (function_exists('file_get_contents')) {
    echo "✅ file_get_contents disponible<br>";
}

// Test JSON
if (function_exists('json_encode')) {
    echo "✅ JSON disponible<br>";
}

// Test HTTP requests
echo "<br><h3>Test d'envoi à Telegram :</h3>";
$token = "VOTRE_TOKEN_BOT"; // Remplacez par votre token
$chat_id = "VOTRE_CHAT_ID"; // Remplacez par votre chat_id

// Test simple
$url = "https://api.telegram.org/bot$token/getMe";
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
$result = curl_exec($ch);
$http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);

if ($http_code == 200) {
    echo "✅ Connexion à Telegram OK<br>";
} else {
    echo "❌ Erreur connexion Telegram (HTTP $http_code)<br>";
}

// Afficher les erreurs PHP
echo "<br><h3>Erreurs PHP détectées :</h3>";
if (error_get_last()) {
    echo "<pre style='color:red'>";
    print_r(error_get_last());
    echo "</pre>";
} else {
    echo "Aucune erreur PHP majeure<br>";
}
?>
