I’m using the Kirby session to store a value for the view mode of the site. This value is modified via an ajax call when you click on the change view button. It seems to work just fine in my local copy and on the server: the view value is successfully saved and kept until the next page load, as desired.
However, for some strange reason, the same is not the case for my client. When he navigates the same server version of the site, the view value is always the initial value. I’ve outputted some values through the console for him to check and he has confirmed that the ajax call gets the correct values returned.
I thought the session was a server thing, so I don’t get why two users would get different outcomes when navigating the same site.
So I output result to the console and both me and my client see the expected value. The difference is in my case it stays and is outputted by the next $kirby->session()->get( 'view' ) while in the case of my client, it doesn’t, and outputs the initial value.
But yet this is the first time I use Kirby Sessions so maybe I’m missing on something very obvious. Could somebody guide me in how to debug this?
Hmm, good point. I was just concerned I would have to add an “allow cookies?” message, but after some research about it, that’s not necessary for “strictly necessary” cookies like this one. I’ll try cookies and if the problem persists, I’ll come back.
about kirby and cookies. the kirby cookie helper adds a hash to its value. this is good if you only use it in php but it means you can not use it to exchange data from js to kirby using that helper.
What I do is manipulate the cookie using PHP code that I execute through a JS ajax call. So even though JS is part of the operation, it doesn’t mess with the cookie directly. If I understand correctly, this means I can safely rely on Kirby’s Cookie Class, right?
Had to still use Kirby’s Cookie::remove() to get rid of the old cookie, which, even though had the same name as the new one, the browser would consider them different. But that was presumably due to how the domain was written in the cookie (for some reason your code window.location.hostname gives me a domain starting with a dot, like .domain.com).
Couldn’t Kirby have more documentation on how to use the Cookies helper? Is it written anywhere that a hash is added to the cookie value?