K
K
koi com2015-01-12 18:03:32
PHP
koi com, 2015-01-12 18:03:32

How to 100% remove cookies on the client side?

they say to do it like this:

setcookie("user_id", "", time() - (365*24*60*60) );
  setcookie("username", "", time() - (365*24*60*60) );
  header("Location: " . "http://localhost/studyphp/index.php");
  exit();

but it doesn't lead to anything. when directed to index.php. index.php checks the cookie and if a user ID is given, it redirects to the personal account. So, after "deleting" the cookie, instead of getting to the authorization page, the user enters the personal account. I don't know how to remove them. And can you tell me how to view cookies in firefox?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
N
nowm, 2015-01-12
@nowm

It seems to me that storing user_id in cookies is not a good idea. In this situation, nothing will prevent the user from setting himself the user_id of the administrator on his side and doing everything that the administrator can do.
It is best to store the user ID in the session ( $_SESSION['user_id']), since the user cannot directly change this ID (hijacking the session will be more difficult than replacing the user_id in the cookie). And any user data, like user_name, is better to store in the database and pull it out when required. In cookies, again, which are completely in the power of the user, it is better not to store this.
And then, when you need to log out the user, just destroy the session and that's it.
You don't even need to destroy a cookie with a session identifier using setcookie, since after the session is destroyed, it doesn't matter what is stored in the cookie. When you create a new session, the cookie will simply be replaced with the cookie with the new session ID.
In Firefox, you can view cookies using the Firebug extension. All cookies for the current page are located in the "Cookies" tab of the Firebug panel, which is opened by pressing the F12 key.

S
SToRm1k, 2015-01-12
@SToRm1k

if ($_COOKIE['user_id'] AND $_COOKIE['username']) {
  setcookie ('user_id', '', time() - 365*24*60*60, '/');
  setcookie ('username', '', time() - 365*24*60*60, '/');
}
header('Location: /index.php');
exit;

E
Eugene, 2015-01-12
@Nc_Soft

if (isset($_COOKIE['user_id'])) {
    unset($_COOKIE['user_id']);
    setcookie('user_id', null, -1, '/');
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question