<?php
// get/change_lang.php
require_once '../config/config.php';

if (!isset($_SESSION['user_id'])) {
    header('Location: ../index.php');
    exit;
}

 $lang = $_GET['lang'] ?? 'id';
if (in_array($lang, ['id', 'en'])) {
    $_SESSION['lang'] = $lang;
    
    // Save to DB
    $stmt = $pdo->prepare("UPDATE users SET lang = ? WHERE id = ?");
    $stmt->execute([$lang, $_SESSION['user_id']]);
}

header('Location: ' . $_SERVER['HTTP_REFERER']);
exit;
?>