Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You can do it a number of ways, either multiple cookies, or storing an Object like JSON, or you could just simply put a string delimited by something like :: for example and user php's eplode function. All in all its a matter of preference and dependent upon what your doing. If you use a JSON object you could easily switch back and forth between the object and an array as well through the use of json_encode and json_decode. Again its all about where your comfort level is. All in all though your looking at working with an array of data in the end if you really want to keep it in a single cookie.</p> <p>Example:</p> <pre><code>&lt;?php //set the cookie $cookieData = json_encode(array("value_one", "value_two")); setcookie("MyCookie", $cookieData , time()+3600); //read the cookie $cookieInfo = json_decode($_COOKIE['MyCookie']); echo $cookieInfo[0]."&lt;br&gt;"; echo $cookieInfo[1]."&lt;br&gt;"; //or for($i = 0; $i &lt; count($cookieInfo); $i++) { echo $cookieInfo[$i]."&lt;br&gt;"; } </code></pre> <p>You can make this concept fairly large, but bare in mind cookies are easily manipulated client side so sanitize your cookie variables before running them through script that can be injected and broken for other needs, example checking a database to see if a use is valid via cookie information. </p> <p>Another thing to remember is some browsers have a cookie size, you where the max size of a cookie is 4kb only. </p> <p>Also you can get a little more fancy with the logic of using JSON and Arrays, they are tricky at first if your not familiar with them but once you start using them and understand them, you will find they are your best friends.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload