chris97ong
chris97ong

Reputation: 7060

php - Cookie value gets changed to different value

I set my cookie with PHP like this:

setcookie(
"hero",
", Comma . Dot < Left > Right - Dash _Underline / Slash \\ Backslash",
time() + (10 * 365 * 24 * 60 * 60));

But somehow, this is the value of the cookie:

%2C+Comma+.+Dot+%3C+Left+%3E+Right+-+_Underline+%2F+Slash+Backslash

And not:

, Comma . Dot < Left > Right - Dash _Underline / Slash \ Backslash


Strangely, I tried to get the cookie value like this:

echo $_COOKIE["hero"];

And that resulted in:

, Comma . Dot < Left > Right - Dash _Underline / Slash \ Backslash


Why is this so?

Upvotes: 2

Views: 818

Answers (2)

A l w a y s S u n n y
A l w a y s S u n n y

Reputation: 38502

You can set raw cookie then value will remain unchanged, Then value will not be automatically urlencoded when sent to the browser. for more info

http://www.php.net//manual/en/function.setrawcookie.php

Upvotes: 1

Locke
Locke

Reputation: 671

PHP automatically url encodes the value portion of a cookie when it is set.

Read the PHP Manual entry on setcookie();

Upvotes: 2

Related Questions