Disable setting language cookie for curl or clients without user agents

This commit is contained in:
Joshua Ramon Enslin 2022-03-26 16:49:10 +01:00
parent 8d7b270f6f
commit 6a7b8bd8fd
Signed by: jrenslin
GPG Key ID: 46016F84501B70AE

View File

@ -428,6 +428,12 @@ final class MD_STD {
}
else {
$lang = self::lang_getfrombrowser($allowed_langs, $default_lang, "", false);
// If the user is a bot or has no user agent at all or one of curl's,
// setting a cookie usually makes little sense.
// On the other hand, setting the cookie prevents effective caching.
if (empty($_SERVER['HTTP_USER_AGENT']) || substr($_SERVER['HTTP_USER_AGENT'], 0, 5) === 'curl/') return $lang;
if (!setcookie('__Host-lang', $lang, $cookie_options)) {
throw new Exception("Failed to set language");
}