-2

I am setting a cookie using $.cookie

$.cookie('enc_an', 'awgWTY5CnJr0f4WD0wU4HH+sAupxj459YNb7Q=', {path: '/'});

But when i echo it on other page it gives different Output

echo $_COOKIE['enc_an']; //Outputs : awgWTY5CnJr0f4WD0wU4HH sAupxj459YNb7Q=

when i inspect cookie Value it is URL encoded

awgWTY5CnJr0f4WD0wU4HH%2BsAupxj459YNb7Q=
N Kumar
  • 1,302
  • 1
  • 18
  • 25
  • 2
    Duplicate http://stackoverflow.com/questions/18653252/why-is-this-2b-string-being-urldecoded – PeeHaa Oct 30 '14 at 16:44
  • yes i may be duplicate but i cannot find answer or solution to this problem.. i have seen that question – N Kumar Oct 30 '14 at 16:46

1 Answers1

1

By default the cookie value is encoded when writing using encodeURIComponent. This can be bypassed by setting by setting raw to true:

$.cookie.raw = true;
$.cookie('enc_an', 'awgWTY5CnJr0f4WD0wU4HH+sAupxj459YNb7Q=', {path: '/'});
cOle2
  • 4,725
  • 1
  • 24
  • 26
  • if i dont want to use raw, can i get the string back – N Kumar Oct 30 '14 at 16:59
  • 1
    Without `raw=true` you would use `urldecode` on the PHP side of thing: `echo urldecode($_COOKIE['enc_an']);` – cOle2 Oct 30 '14 at 17:01
  • No i am not getting + back it is outputting space – N Kumar Oct 30 '14 at 17:06
  • `urldecode($_COOKIE['enc_an']) == "awgWTY5CnJr0f4WD0wU4HH+sAupxj459YNb7Q="` but its echo is showing space not + . Any ways i dont want to echo hence.. i got my solution. Thank You – N Kumar Oct 30 '14 at 17:26