Hello,
I need some advice...
For a webservice, I have to change the interface dynamically depending on user choices.
As Javascript is the perfect language for this, I also use it to store instantly in cookies the changes that occurs.
This sounds logical to me, but
I want to be sure that I did the right choice and that I should not use PHP session cookie variables instead.
I want all user preferences to be stored 3 days or even more. (The risk of erasing cookies is not important in this case.)
The cookies that I write in Javascript are without time limit.
I read somewhere that such cookies are destroyed when the session ends. So, this would suit my needs.
I’m however not sure if the word "session" here relates to a PHP session or something else, and what happens if no PHP session is created.
Currently, I set PHP session duration with
ini_set('session.gc_maxlifetime', '259200'); // 3 days
Then, I create or get existing session in PHP with session_start().
Lastly, I check if cookies are enabled (SID must be null).
Concerning PHP session cookies, I am wondering if all the session variables are stored in a unique session cookie (and PHP parse it to extract the variables) or if PHP creates as many cookies as there are session variables to store.
I ask this because of the 20 cookies/domain limit.
I hope that I can keep my Javascript based approach.
Currently my cookies store composite information (because of the 20 cookies limit) and I parse the cookies content to get key-value pairs.
Are there major drawbacks in setting cookies with Javascript ?
Thanks sharing your experience.
Javascript based approach (with custom functions) :
WriteACookie('someKeyValuePairs', value);
// Read cookie value that will be parsed afterwards
var cookieContent = ReadACookie('someKeyValuePairs');
PHP based approach:
<?php
$_SESSION['variable'] = $valeur ;
if(isset($_SESSION['variable']))
valeur = $_SESSION['variable'];
?>