Detect Browser Language in PHP

后端 未结 13 1225
孤城傲影
孤城傲影 2020-11-22 09:16

I use the following PHP script as index for my website.

This script should include a specific page depending on the browser\'s language (automatically detected).

相关标签:
13条回答
  • 2020-11-22 09:55

    I've got this one, which sets a cookie. And as you can see, it first checks if the language is posted by the user. Because browser language not always tells about the user.

    <?php   
        $lang = getenv("HTTP_ACCEPT_LANGUAGE");
        $set_lang = explode(',', $lang);
        if (isset($_POST['lang'])) 
            {
                $taal = $_POST['lang'];
                setcookie("lang", $taal);
                header('Location: /p/');
            }
        else 
            {
                setcookie("lang", $set_lang[0]);
                echo $set_lang[0];
                echo '<br>';
                echo $set_lang[1];
                header('Location: /p/');
            } 
    ?>
    
    0 讨论(0)
提交回复
热议问题