I have developed a New Website in HTML. Its a Multi Location or Country Website. For the same I have created the Welcome Page where it will show the list of countries available and I need to place a Remember me Check box so that next time the same computer visit my website it will not have to choose its country and will be directed to the country which it had chosen earlier.

Please tell me How can I place a cookie there. Really I don't have any Idea about cookies nor I know how to create them.

Please help me.

Dani AI

Generated

For 's multi-country welcome page the simplest reliable pattern is: when the visitor chooses a country and checks "Remember me", save a small persistent cookie (for example country=US). On subsequent visits read that cookie and auto-redirect to the saved country. As noted, this is a JavaScript task; as pointed out, there are many examples online — here's a compact, practical implementation to drop into the welcome page.

function setCookie(name, value, days) {
  var expires = "";
  if (days) {
    var date = new Date();
    date.setTime(date.getTime() + days * 24 * 60 * 60 * 1000);
    expires = "; expires=" + date.toUTCString();
  }
  document.cookie = name + "=" + encodeURIComponent(value) + expires + "; path=/";
}

function getCookie(name) {
  var nameEQ = name + "=";
  var ca = document.cookie.split(';');
  for (var i = 0; i < ca.length; i++) {
    var c = ca[i].trim();
    if (c.indexOf(nameEQ) === 0) return decodeURIComponent(c.substring(nameEQ.length));
  }
  return null;
}

/* Example usage:
   setCookie('country', 'US', 365);      // when "Remember me" is checked
   var country = getCookie('country');   // on welcome page load
   if (country) window.location.href = '/' + country + '/';
*/

Notes and cautions: add ; domain=.example.com to the cookie string if the cookie must be visible to subdomains. JavaScript cannot create an HttpOnly cookie (that must be set by the server). Avoid storing sensitive data in client-side cookies — store a short code or token if needed. Typical browser limits are about 4096 bytes per cookie and a limited number of cookies per domain. For purely client-side preferences, localStorage is an alternative that isn’t sent with every request.

Troubleshooting: cookies won’t persist on file:// pages — test on an http(s) host. Use browser devtools (Application/Storage → Cookies) to inspect name/value, path, domain and expiry. If a cookie is missing, check SameSite/Secure requirements, domain/path mismatch, private-mode cookie blocking, or incorrect expiration formatting.

Recommended Answers

All 5 Replies

This is more of a JavaScript problem. If you do a google search of cookies and JavaScript, you should get many hits, I am sure there are a lot of handy examples there. Let me know if you struggle to get things working.

What do I search ? Wht kind of Java script should I search, Where can I get the java script ?

This is more of a JavaScript problem. If you do a google search of cookies and JavaScript, you should get many hits, I am sure there are a lot of handy examples there. Let me know if you struggle to get things working.

What do I search ? Wht kind of Java script should I search, Where can I get the java script

haha murtan, that website is gold!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.