User with browser cookies disabled

Asked

Viewed 78 times

1

I have a system and use cookies to temporarily store information, but I noticed a problem with a certain user and when trying to solve the problem, I noticed that the cookies disabled (do not ask me why).

I serve cookies conventionally by php

setcookie(...);

So these are my questions:

  1. How do I know if a user has disabled browser cookies?
  2. If so, how should I proceed?
  • 1

    It would not be the case to record and try to recover a cookie precisely to make the diagnosis and then warn the user that the site requires the enabling of cookies or even block access to the system?

  • In a way yes, @Leandroangelo

1 answer

1


I think with PHP it won’t be possible, but you can try javascript, something like:

<script type="text/javascript">

var tmpcookie = new Date();

chkcookie = (tmpcookie.getTime() + '');

document.cookie = "chkcookie=" + chkcookie + "; path=/";

if( document.cookie.indexOf(chkcookie,0) < 0 )
{
    alert('Cookie desabilitado');
}
else
{
    alert('Cookie habilitado');
}

</script>

Reference

  • It’s a good solution. It hadn’t even crossed my mind. Thank you!

  • 1

    You’re welcome. Remember, PHP is a server-side. There’s hardly anything in it for things that are handled in client-side.

  • Well remembered hahaha

Browser other questions tagged

You are not signed in. Login or sign up in order to post.