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

  • Home
  • SEARCH
  • 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 8925637
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T07:45:12+00:00 2026-06-15T07:45:12+00:00

Possible Duplicate: Allowed characters in cookies I’m using JSON.stringify to convert an object to

  • 0

Possible Duplicate:
Allowed characters in cookies

I’m using JSON.stringify to convert an object to save it in a cookie. But after saving Arabic Windows-1256 encoding in a cookie, I wasn’t able to restore it. Here’s what I did:

For example:

Convert and save in a cookie.

conv[user]   = {"user":1,"u":1,"m":3,"c":255,"comment":'السلام عليكم ورحمه الله'};
addCookie('chat_conversations', JSON.stringify(conv) , 7);

Restore value from cookie:

var con  = is_cookie('chat_conversations');
conv = jQuery.parseJSON(con);

Getting my JSON result:

alert(conv[1].comment);

Result

“‘D3D’E 9DJCE H1-EG ‘DDG H(1C’*G\n”

Here’s the result of my cookie

chat_conversations={“1”:{“user”:”1″,”u”:”1″,”m”:3,”c”:255,”comment”:”‘D3D’E 9DJCE H1-EG ‘DDG H(1C’*G\n”}}; expires=Sat, 08 Dec 2012 15:00:42 GMT; path=/; domain=127.0.0.1

How can I save an object containing Arabic in a cookie and restore it?

  • 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-06-15T07:45:13+00:00Added an answer on June 15, 2026 at 7:45 am

    You should sanatise strings going into a cookie using escape or encodeURIComponent (minor differences between the two, see below) and then reverse this via unescape or decodeURICompontent when retrieving the data.

    // Create obj using safe chars only
    conv[user] = {
        "user" : 1, // (numbers are fine as they are)
        "u" : 1,
        "m" : 3,
        "c" : 255,
        "comment" : escape('السلام عليكم ورحمه الله') // by escaping potentially unsafe chars
    };
    // save
    addCookie('chat_conversations', JSON.stringify(conv) , 7);
    // retrieve
    var con  = is_cookie('chat_conversations');
    conv = jQuery.parseJSON(con);
    
    var comment = unescape(conv[1].comment); // unescape what was escaped earlier
    alert(comment);
    // "السلام عليكم ورحمه الله"
    

    escape is fine because you just want to use this data in JavaScript. If you want to access the cookie server-side then I’d strongly recommend using encodeURIComponent.

    If you are just using it for JavaScript, consider window.localStorage because it will cause less internet usage.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: What characters are allowed in C# class name? I'm using edmgen to
Possible Duplicate: Firefox session cookies I'm creating a website in which users are allowed
Possible Duplicate: @SuppressWarnings for “extends String” Why T extends String is allowed but gives
Possible Duplicate: What characters are allowed in email address? I have an email address
Possible Duplicate: How do I make a request using HTTP basic authentication with PHP
Possible Duplicate: How can I convert a list<> to a multi-dimensional array? I want
Possible Duplicate: Is it allowed to name the parameter in postfix operator ++? I
Possible Duplicate: Why aren't static const floats allowed? Is there any reason why this
Possible Duplicate: Using regular expression within a stored procedure I need to validate a
Possible Duplicate: Why is a class allowed to have a static member of itself,

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.