1

I am using sessions to store user's login and registering data. If cookies are off in user's browsers it doesn't work.

Is that possible to show them a message if their cookies are off and give them the option to press ok to enable it or there is another way to solve that problem.

Fabiano Araujo
  • 876
  • 6
  • 19
M.abdelrhman
  • 958
  • 14
  • 24

2 Answers2

1

If the user has cookies turned off in their browser, there's nothing the server can do to turn them on. Yes, you can prompt the user to change their settings, but your code won't be able to do it.

If they have cookies turned off, you need to pass the session ID as a GET parameter - with all of its security problems, etc. You are better off telling them (in your prompt) "Look, you really need to have cookies enabled, or the site isn't going to work right - you won't be able to log in, etc. etc."

FKEinternet
  • 1,050
  • 1
  • 11
  • 20
  • is it possible to to give them okay button if they clicked it the cookies would be enabled? – M.abdelrhman Jul 15 '17 at 13:29
  • You could give them instructions on how to enable cookies in their browser (different directions for each browser they might use, good luck with that), but no, you cannot, from the server, turn on cookies or change any other user-configurable settings in their browser. If you could, it would be a *MAJOR* security hole in the browser design. – FKEinternet Jul 15 '17 at 13:32
1

The simplest way to do this would be to set a cookie and use PHP's isset to see if it exists, but you can't change it for the user simply because of security purposes. Regardless, here is a way to see if cookies are enabled.

Set the cookie:

<?php
    setcookie(name, value, time() + (86400 * 30), "/");
    header("Location: cookieCheck.php");
?>

cookieCheck.php:

<?php
    if(!isset($_COOKIE['name'])) {
        echo "Cookies are not enabled on your browser, please turn them on!";
    }
?>

Hope this helps you!

HoogleyBoogley
  • 340
  • 2
  • 14