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 8914357
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T04:42:08+00:00 2026-06-15T04:42:08+00:00

Ok, so I had an odd requirement on a recent project. In order to

  • 0

Ok, so I had an odd requirement on a recent project. In order to get around limitations of our CMS and caching I needed to store and update a JSON object in a cookie after making several AJAX calls. Later if a user completed a process the information stored in this cookie is used to identify choices made earlier. The completion can span a few minutes to several weeks, ie. page conversion with virtually no time restriction.

When I went to extract the encoded JSON string from the $_COOKIE global I started getting JSON Syntax errors (actually the bugs cropped up before that point but that is when I started to figure out what was happening). I was using the built-in JSON.stringify in Javascript to set the cookie value, and json_decode in PHP.

Apparently, PHP will escape the quotes in a string value coming out of $_COOKIE, this caused the JSON syntax error, and the cascade effect after. I did not see any mention in the PHP JSON functions or $_COOKIE docs. I ended up doing a preg_replace on the ‘\’ and removing them, and it ‘works’ now.

That seems to be like a hacky work around. Was/is there something I am missing? Is there a better way to do this in the future?

when echoing the values and json_last_error():

$cookie = $_COOKIE[‘cookie_name’]; => {\”suffix\”:\”general\”…}
$cookie = json_decode($cookie, true); => Syntax Error: NULL
$cookie = preg_replace(‘/\\/’, “”, $cookie); => {“suffix”:”general”…}
$cookie = json_decode($cookie, true); => No Errors: ARRAY

  • 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-15T04:42:10+00:00Added an answer on June 15, 2026 at 4:42 am

    you need to add the second parameter of json_encode as (some constants need PHP 5.3)

    json_encode($data, JSON_HEX_QUOT | JSON_HEX_TAG | JSON_HEX_AMP | JSON_HEX_APOS | JSON_HEX_QUOT);
    

    also, you’ll need json_decode(stripslashes($json)) since it seems magic_quotes_gpc is on

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

Sidebar

Related Questions

I just had the odd case that my Android project for some reason would
I've got a really odd issue that I've not had any success googling for.
This is very odd. I have never had this issue with ShowDialog in C#.
Had to download Command Line Tools from Apple to get make to work, but
I recently moved to a project where I noticed there have a specific requirement
Has anybody else had problem with position() working odd in IE? I'm trying to
When reviewing code I came across something odd, someone had read that you can
I had an odd problem today when I was trying to serialize an object.
We had a designer redo our site and he tried 4 or 5 different
I've had a very odd learning experience in programming. I was sort of taught

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.