<?php
require_once __DIR__ . '/../includes/i18n.php';

$lang = $_GET['lang'] ?? 'en';
if (!in_array($lang, SUPPORTED_LANGS, true)) $lang = 'en';

setcookie('ky_lang', $lang, [
    'expires' => time() + 60 * 60 * 24 * 365,
    'path' => '/',
    'samesite' => 'Lax',
]);

$redirect = $_GET['redirect'] ?? '/';
// Only allow local redirects to avoid an open-redirect vector.
if (strpos($redirect, '/') !== 0 || strpos($redirect, '//') === 0) $redirect = '/';

header('Location: ' . $redirect);
exit;
