Javascript / PHP cookie serialization methods?

I have a form that I would like to store values ​​in a cookie so that the user does not have to re-enter the form in every visit. (A form is a few selections for filtering search results.)

I would like the cookie serialization to be easy to read from javascript (obviously to set the onLoad form), but I would also like to be able to read cookies easily with PHP (so that I can use the form data to filter the search results).

How would I start serializing a form with selections that have multiple = "multiple" set in a cookie, and is it easy to read in javascript and PHP?

Please do not preach about verification, I am doing it right on the server side.

If there is a more reasonable solution to my problem, please let me know.

BTW: I use CodeIgniter on the server and the prototype / Scriptaculous javascript libraries.

Solution: Used a prototype for javascript and used PHP to get an associative array in PHP from JSON.Object.toJSON( Form.serialize(form, true))json_decode(string, bool)

+3
source share
2 answers

You can use the JSON format , which is already implemented in several languages.

+6
source

I would recommend YAML. It is mainly designed as a regular serialization method for several languages, including JavaScript and PHP.

From the YAML website:

YAML Perl, Python, Ruby, Tcl, PHP, Javascript Java. . YAML Perl, Python.

:

http://www.sitepoint.com/blogs/2004/04/22/serializing-php-data-structures-for-javascript/

YAML:

http://www.yaml.org/

+1

Source: https://habr.com/ru/post/1704854/


All Articles