Cookie not working after mod rewrite rule

Posted by moonwalker on Stack Overflow See other posts from Stack Overflow or by moonwalker
Published on 2010-12-24T03:26:16Z Indexed on 2010/12/24 3:54 UTC
Read the original article Hit count: 278

Filed under:
|
|

Hi all,

I have a simple Cookie 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*365;

// 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);

No luck at all.

This is my .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>

Any idea how to solve this? I'm still new to the mod rewrite thing, so I still don't really understand the logic behind it all.

Thanks for any help you can provide.

© Stack Overflow or respective owner

Related posts about php5

Related posts about mod-rewrite