Answer the question
In order to leave comments, you need to log in
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();
Answer the question
In order to leave comments, you need to log in
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.
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;
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question