Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 5967125
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T19:53:56+00:00 2026-05-22T19:53:56+00:00

I have a multilingual website with the possibility to switch between German and English.

  • 0

I have a multilingual website with the possibility to switch between German and English. I want to store the chosen language in a cookie so that the visitor don’t have to switch it over and over again to his prefered language when he visits the website next time. Unfortunately I have a strange behaviour with that. It looks like this:

I have a link for switching the language (onclick). This function looks like this:

function storeLanguage(lang)  {
    /*deletes the cookie? */
    document.cookie = "MYCOOKIE=; expires=Thu, 01-Jan-70 00:00:01 GMT;";
    var ablauf = new Date();
    var expTime = ablauf.getTime() + (60 * 24 * 60 * 60 * 1000); //Cookie for 60 days
   ablauf.setTime(expTime);

   if (lang == 'en')  {
            document.cookie = "MYCOOKIE=EN; expires=" + ablauf.toGMTString() + ";";
   }
   else  {
       document.cookie = "MYCOOKIE=DE; expires=" + ablauf.toGMTString() + ";";
   }
}

Firebug says that it jumps into the right IF-branch, so when I click “German”, this part will be executed “MYCOOKIE=DE”, otherwise the english branch. This looks right. But when I get to any web page of my website (for test I chose the index site) and execute an

alert(document.cookie);

I suddendly get as result at the German web page “MYCOOKIE=EN”, although it should be “MYCOOKIE=DE” because the function jumped into the right IF-branch (else branch). When I switch to English language, I get as result on the english web page “MYCOOKIE=DE; MYCOOKIE=EN”. So suddendly there are two cookies with the same name. So the values of the cookies are not just inverted, and not deleted right, but totally crap. Can anybody explain what’s wrong in my code which leads to this behaviour?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T19:53:57+00:00Added an answer on May 22, 2026 at 7:53 pm

    Make sure that you are properly setting the path of the cookie as well. For example if the language of your site is embedded in the URL (IE: http://yoursite.com/en/index.html), you may be setting a cookie to only be valid if the path contains “/en”. Full cookie setting syntax looks like this:

    document.cookie = 'mycookie=somevalue; expires=Thu, 2 Aug 2001 20:47:11 UTC; path=/'
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hi i have develop and deploy one multilingual (english uk and swedish) website at
I have multilingual website in joomla and want to hide one menu item (not
I have a multilingual website (Chinese and English). I like to validate a text
I have a multilingual website with 2 languages: en (default) and de (german). I
We are now using Django to develop a multilingual website. We have different language
I'm building a multilingual website that uses PHP to load language files. Paragraphs in
I have a multilingual blog, default language is Italian and second language is English.
I have a multilingual website with English and Arabic support. The URL of a
I have a multilingual website and. Htaccess, which displays all the pages. I want
I'm using the Google CSE to search through a multilingual website (german, english, dutch,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.