/    Sign up×
Community /Pin to ProfileBookmark

Can’t decode json array stored in cookie

Hi, I am storing a json array in a cookie.

I later want to reassemble this array.

The json value in the cookie looks like this:

{“path”:”/home/stuff/”,”params”:[]}

When i try to use json_decode($_COOKIE[‘my_cookie’]) it returns nothing.

However, if i echo out the cookie value and then manaully paste it into the json_decode() surrounded by double quotes, it parses it fine.

Can anyone help me figure out why? I’ve tried used (string) before the cookie value.

to post a comment
PHP

1 Comments(s)

Copy linkTweet thisAlerts:
@coldscooterauthorAug 15.2011 — I figured out it was caused by my server having get_magic_quotes_gpc() enabled.

I fixed it by using: stripslashes($_COOKIE['cookie_name'])

Or if you have alternating server configs, you can use:

if (get_magic_quotes_gpc()) {

$some_array = stripslashes($_COOKIE['cookie_name']);

}
×

Success!

Help @coldscooter spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.18,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...