<?php
$jsonFile = "deppo/subdomains.json";
$rsd = null;

if (file_exists($jsonFile)) {
    $domains = json_decode(file_get_contents($jsonFile), true);
    $currentDomain = strtolower(str_replace("www.","", $_SERVER['SERVER_NAME']));

    foreach ($domains as $domain) {
        if (strtolower($domain["domain"]) === $currentDomain) {
            $rsd = $domain;
            break;
        }
    }
}

// Domain JSON'da yoksa artık script durmuyor, $rsd = null kalıyor
if ($rsd) {
    foreach($locations as $location){
        if($location["t1"]==$rsd["sub_location"]){
            $ltype=$location["ne"];
            if($ltype=="ulke"){$countryID=$location["id"];}
            if($ltype=="il"){$provinceID=$location["id"]; $countryID=$location["s1"];}
            if($ltype=="ilce"){$districtID=$location["id"]; $countryID=$location["s1"]; $provinceID=$location["s2"];}
            if($ltype=="semt"){$neighborhoodID=$location["id"]; $countryID=$location["s1"]; $provinceID=$location["s2"]; $districtID=$location["s3"];}
        }
        if(isset($countryID) && $location["id"]==$countryID){ $country=$location["t1"]; }
    }

    $lcountry = $country ?? null;
    $lang = $rsd["table"];
    $city = $rsd["sub_location"];
    $lcity = $rsd["location"];
    $trns = $rsd["lang"];
    $User_s19 = $rsd["n6"];

    $_SESSION["lang"] = $rsd["table"];
} else {
    // Domain JSON'da yoksa buraya düşer, varsayılan değerler atanabilir
    $lcountry = null;
    $lang = "tr"; // veya default dil
    $city = null;
    $lcity = null;
    $trns = null;
    $User_s19 = null;

    // $_SESSION["lang"] = "tr"; // default dil olarak
}
?>