I'm creating a very basic message board type of thing and want to show new posts since as user's last visit. I'm looking to use Cookies, but need some help with the logic.

Should I be setting a cookie when the user visits, and then retrieve that next time and delete the previous one? If so, how can I set the expiration for next session? Would I leverage the Craft login session. This will only be for logged in users, so can I leverage that?

{% do craft.cookies.set('userReturns', 'userReturns', now | date_modify("+5 minutes").timestamp) %}
{% set timestamp = getCookie('userReturns') %}
{% if element.postDate >= timestamp %}
{% endif %

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.