PHP - 简单的Cookie不保存(Wordpress)

时间:2016-06-03 13:10:10

标签: php wordpress cookies setcookie

我尝试制作语言Cookie,但由于某种原因,Cookie无法保存。

这里是我使用

的代码
if ( !empty($_GET['language']) ) {
    setcookie('language-eclear', $_GET['language']);
}


if ( empty($_COOKIE['language-eclear']) ) {
    $lang = substr($_SERVER['HTTP_ACCEPT_LANGUAGE'], 0, 2);
    switch ($lang){
        case "fr":
            include("langFiles/lang-indexFR.php");
            break;
        case "de":
            include("langFiles/lang-indexDE.php");
            break;
        case "en":
            include("langFiles/lang-indexEN.php");
            break;
        case "nl":
            include("langFiles/lang-indexNL.php");
            break; 
        default:
            include("langFiles/lang-indexEN.php");
            break;
    }
}else{
    $lang = $_COOKIE['language-eclear'];
    switch ($lang){
        case "fr":
            include("langFiles/lang-indexFR.php");
            break;
        case "de":
            include("langFiles/lang-indexDE.php");
            break;
        case "en":
            include("langFiles/lang-indexEN.php");
            break;
        case "nl":
            include("langFiles/lang-indexNL.php");
            break; 
        default:
            include("langFiles/lang-indexEN.php");
            break;
    }
}
?>

用于设置Cookie工作的if循环我通过echo&em> $ _ GET ['语言']; 测试了它。

然而,似乎cookie并没有节省。我错过了什么?

PS:我正在使用wordpress网站

0 个答案:

没有答案