<?php
header('Content-Type: text/plain');

// Nominatim URL (Strukturierte Suche nach Berlin)
$url = "https://nominatim.openstreetmap.org/search?city=Berlin&format=json&limit=1";

function nominatim_test($name, $options) {
    global $url;
    echo "Teste $name... ";
    
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    // Nominatim verlangt zwingend einen User-Agent!
    curl_setopt($ch, CURLOPT_USERAGENT, 'StolpersteinApp-Validator-Test (dein-name@example.com)');
    
    if (!empty($options)) {
        curl_setopt_array($ch, $options);
    }
    
    $result = curl_exec($ch);
    $info = curl_getinfo($ch, CURLINFO_HTTP_CODE);
    $error = curl_error($ch);
    curl_close($ch);
    
    if ($info == 200) {
        echo "ERFOLG! (HTTP 200)\n";
    } else {
        echo "FEHLER: Code $info - $error\n";
    }
}

echo "NOMINATIM DIAGNOSE START\n";
echo "------------------------\n";

// Test 1: Standard mit korrektem User-Agent
nominatim_test("Standard (mit User-Agent)", []);

// Test 2: Nur IPv4 (oft die Lösung bei 'Connection refused')
nominatim_test("Zwinge IPv4", [
    CURLOPT_IPRESOLVE => CURL_IPRESOLVE_V4
]);

// Test 3: Ohne SSL-Prüfung
nominatim_test("Ohne SSL-Prüfung", [
    CURLOPT_SSL_VERIFYPEER => false
]);

echo "------------------------\n";
echo "TEST ENDE";
?>