mod 重写规则后 Cookie 不起作用

发布于 2024-10-08 18:05:01 字数 1489 浏览 5 评论 0原文

我有一个简单的 cookie 用于设置所选语言:

$lang = $_GET['lang'];
$myLang = $_COOKIE["myLang"];

if (!isset($_COOKIE["myLang"])){
    setcookie("myLang", "en", $expire);
    include "languages/en.php";
    $myLang = "en";
    }else{
    include "languages/$myLang.php";
}

// One year to expire
$expire = time()+60*60*24*30*12;

// Put $languages in a common header file.
$languages = array('en' => 1, 'fr' => 2, 'nl' => 3);

if (array_key_exists($lang, $languages)) {
    include "languages/{$lang}.php";
    setcookie("myLang", $lang, $expire);
    $myLang = $lang;
}

使用一些重写规则后,它不再起作用了。我尝试了以下操作:

setcookie("myLang", "en", $expire, "/" , false);

.htaccess 文件:

<IfModule mod_rewrite.c>
    Options +FollowSymLinks
    Options +Indexes
    RewriteEngine On
    RewriteBase /
    RewriteRule ^sort/([^/]*)/([^/]*)$ /3arsi2/sort.php?mode=$1&cat=$2 [L]
    RewriteRule ^category/([^/]*)$ /3arsi2/category.php?cat=$1 [L]
    RewriteRule ^category/([^/]*)/([^/]*)$ /3arsi2/category.php?cat=$1&lang=$2 [L]
    RewriteRule ^search/([^/]*)$ /3arsi2/search.php?mode=$1 [L]
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^u/([^/]+)/?$ 3arsi2/user.php?user=$1 [NC,L]
    RewriteRule ^u/([^/]+)/(images|videos|music)/?$ 3arsi2/user.php?user=$1&page=$2 [NC,L] 
    RewriteRule ^([^\.]+)$ 3arsi2/$1.php [NC,L]
</IfModule>

I have a simple cookie used to set the chosen language:

$lang = $_GET['lang'];
$myLang = $_COOKIE["myLang"];

if (!isset($_COOKIE["myLang"])){
    setcookie("myLang", "en", $expire);
    include "languages/en.php";
    $myLang = "en";
    }else{
    include "languages/$myLang.php";
}

// One year to expire
$expire = time()+60*60*24*30*12;

// Put $languages in a common header file.
$languages = array('en' => 1, 'fr' => 2, 'nl' => 3);

if (array_key_exists($lang, $languages)) {
    include "languages/{$lang}.php";
    setcookie("myLang", $lang, $expire);
    $myLang = $lang;
}

After using some rewrite rules, it just doesn't work anymore. I tried the following:

setcookie("myLang", "en", $expire, "/" , false);

.htaccess file:

<IfModule mod_rewrite.c>
    Options +FollowSymLinks
    Options +Indexes
    RewriteEngine On
    RewriteBase /
    RewriteRule ^sort/([^/]*)/([^/]*)$ /3arsi2/sort.php?mode=$1&cat=$2 [L]
    RewriteRule ^category/([^/]*)$ /3arsi2/category.php?cat=$1 [L]
    RewriteRule ^category/([^/]*)/([^/]*)$ /3arsi2/category.php?cat=$1&lang=$2 [L]
    RewriteRule ^search/([^/]*)$ /3arsi2/search.php?mode=$1 [L]
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^u/([^/]+)/?$ 3arsi2/user.php?user=$1 [NC,L]
    RewriteRule ^u/([^/]+)/(images|videos|music)/?$ 3arsi2/user.php?user=$1&page=$2 [NC,L] 
    RewriteRule ^([^\.]+)$ 3arsi2/$1.php [NC,L]
</IfModule>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

北风几吹夏 2024-10-15 18:05:01

没关系。我只需要执行以下操作:

setcookie("myLang", "en", $expire, "/");

现在一切都恢复正常了。

希望这将来能节省其他人的时间。

和平。

Never mind. I just need to do the following:

setcookie("myLang", "en", $expire, "/");

Now everything is back to normal.

Hopefully this will save someone else time in the future.

Peace.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文