2

When I make a JavaScript cookie like this:

document.cookie = "hh=234,23423,324";

And I read it from PHP like this:

echo ($_COOKIE['hh']);

It is only returning the value: 234 and not: 234,23423,324

In google chrome resources tab the entire value is shown as '234,23423,324'.

Any information is helpful [1]: https://i.sstatic.net/5IpXg.png

0

1 Answer 1

3

You need to store your cookie as a string and not as a number. Otherwise your cookie may be interpreted as number, stopping parsing at first non-digit character.

Try this in JavaScript: document.cookie = 'hh="234,23423,324"';

Read more in Mozilla's cookie documentation.

Sign up to request clarification or add additional context in comments.

4 Comments

it does not seem to be working, when using: document.cookie = 'hh="234,23423,324"'; php output is [hh] => 23
Can you check if your cookie content is 234,23423,324 or "234,23423,324" please ?
When using document.cookie = 'hh="234,23423,324"'; value is: "234,23423,324"
And output from PHP is then: 23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.