Check if cookies are disabled by users browser

Post

Posted
Rating:
#4312 (In Topic #892)
Joe
Avatar
Standard member
Joe is in the usergroup ‘Honoured member’

Using Tempcode?

I'm going to split this post into two questions…

When a user logs in, obviously a cookie is stored, am I correct? But what happens when cookies aren't enabled by the browser – what happens? Does Composr display a message requiring the user to enable cookies or does it somehow allow the user to still login? (I'm not very knowledgeable with cookies).

If Composr allows the user to still login, consider my next question…
I've got some Comcode pages that require input from the user when viewed, and depending on what is inputted by the user will dictate what else is displayed on the page.

For example: One page offers specific instructions to follow based on what U.S. state the user resides in. If the user didn't select a state in their profile, a popup appears on the page requesting them to input their state. Once inputted, the popup disappears and the page reloads – but this time it populates only information specific to the state they chose. This functionality utilizes the overlay system (which stores cookies), however, this system only works if the user has cookies enabled.

I need a way to check if the user has cookies enabled. If not, I'd like to display a message on the Comcode page explaining that the use of cookies are required to even continue.

HOWEVER, if cookies are required from the start (and assuming Composr warns the user if cookies aren't enabled), then my second question would be irrelevant as these Comcode pages are restricted to logged in users anyway, so I wouldn't need to check if cookies are enabled (in theory, they'd already be enabled if Composr requires them right?)
Online now: No Back to the top

Post

Posted
Rating:
#4313
Avatar
Site director
Chris Graham is in the usergroup ‘Administrators’
When cookies are disabled the browser almost always still allows session cookies (removed when the browser is closed).

If Composr detects no cookies are present it will store the session ID in the URL, via the keep_session GET parameter.

Composr detects cookies by setting a cookie named 'has_cookies'.

This obviously doesn't work for the first page view.

So to detect cookies, just detect there are some cookies present already.


Become a fan of Composr on Facebook or add me as a friend. Add me on on Mastodon. Follow me on Minds (where I am most active). Support me on Patreon

Was I helpful?
  • If not, please let us know how we can do better (please try and propose any bigger ideas in such a way that they are fundable and scalable).
  • If so, please let others know about Composr whenever you see the opportunity or support me on Patreon.
  • If my reply is too Vulcan or expressed too much in business-strategy terms, and not particularly personal, I apologise. As a company & project maintainer, time is very limited to me, so usually when I write a reply I try and make it generic advice to all readers. I'm also naturally a joined-up thinker, so I always express my thoughts in combined business and technical terms. I recognise not everyone likes that, don't let my Vulcan-thinking stop you enjoying Composr on fun personal projects.
  • If my response can inspire a community tutorial, that's a great way of giving back to the project as a user.
Online now: No Back to the top

Post

Posted
Rating:
#4314
Joe
Avatar
Standard member
Joe is in the usergroup ‘Honoured member’
So to detect cookies, just detect there are some cookies present already.

Not sure I understand that last bit, but that's okay.

Does Composr show any message asking the user to enable cookies?

I'm glad you informed me of the has_cookies cookie – I can check if this cookie exists using the Tempcode symbol I created, or check if keep_session is non-empty.

So consider this scenario:
User doesn't have cookies enabled but just logged in. User visits my Comcode page (which will check if has_cookies exists). Here I'll display an error that cookies are required. User then enables cookies in their browser.

Here lies a problem – I assume the user would have to log out and back in again in order for has_cookies to be created, yes? If so, I'd have to display an error message to logout and back in again. Do browsers normally require a reset (close and reopen) in order for cookies to enable?
Online now: No Back to the top

Post

Posted
Rating:
#4315
Avatar
Site director
Chris Graham is in the usergroup ‘Administrators’
If there are cookies set, cookies are enabled, if there are no cookies set, cookies are not enabled). That's all I'm saying.

Composr does not require cookies, so doesn't give an error message if they are not enabled.

has_cookies has nothing to do with logins. It is set on every page view.


Become a fan of Composr on Facebook or add me as a friend. Add me on on Mastodon. Follow me on Minds (where I am most active). Support me on Patreon

Was I helpful?
  • If not, please let us know how we can do better (please try and propose any bigger ideas in such a way that they are fundable and scalable).
  • If so, please let others know about Composr whenever you see the opportunity or support me on Patreon.
  • If my reply is too Vulcan or expressed too much in business-strategy terms, and not particularly personal, I apologise. As a company & project maintainer, time is very limited to me, so usually when I write a reply I try and make it generic advice to all readers. I'm also naturally a joined-up thinker, so I always express my thoughts in combined business and technical terms. I recognise not everyone likes that, don't let my Vulcan-thinking stop you enjoying Composr on fun personal projects.
  • If my response can inspire a community tutorial, that's a great way of giving back to the project as a user.
Online now: No Back to the top

Post

Posted
Rating:
#4316
Joe
Avatar
Standard member
Joe is in the usergroup ‘Honoured member’
Aha, gotcha!

So once the user enables cookies and refreshes the page, in theory, the has_cookies cookie should be automatically created, right?
Online now: No Back to the top

Post

Posted
Rating:
#4317
Avatar
Site director
Chris Graham is in the usergroup ‘Administrators’
yes


Become a fan of Composr on Facebook or add me as a friend. Add me on on Mastodon. Follow me on Minds (where I am most active). Support me on Patreon

Was I helpful?
  • If not, please let us know how we can do better (please try and propose any bigger ideas in such a way that they are fundable and scalable).
  • If so, please let others know about Composr whenever you see the opportunity or support me on Patreon.
  • If my reply is too Vulcan or expressed too much in business-strategy terms, and not particularly personal, I apologise. As a company & project maintainer, time is very limited to me, so usually when I write a reply I try and make it generic advice to all readers. I'm also naturally a joined-up thinker, so I always express my thoughts in combined business and technical terms. I recognise not everyone likes that, don't let my Vulcan-thinking stop you enjoying Composr on fun personal projects.
  • If my response can inspire a community tutorial, that's a great way of giving back to the project as a user.
Online now: No Back to the top
1 guest and 0 members have just viewed this.

Statistics

Forum statistics:
  • 2,052 topics, 7,195 posts, 10,830 members
  • Our newest member is Customcollective
Back to Top