I am trying to learn PHP and use sessions. I saw examples of using session_destroy when logging out, but I see this in the php documentation:
To kill a session altogether, as well as to log out, the session identifier must also be canceled. If a cookie is used to propagate the session identifier (default behavior), you must delete the session cookie. Setcookie () can be used for this.
so what should you do when you log out?
, , , , : http://php.net/manual/en/function.session-destroy.php
# 1 $_SESSION<?php // Initialize the session. // If you are using session_name("something"), don't forget it now! session_start(); // Unset all of the session variables. $_SESSION = array(); // If it desired to kill the session, also delete the session cookie. // Note: This will destroy the session, and not just the session data! if (ini_get("session.use_cookies")) { $params = session_get_cookie_params(); setcookie(session_name(), '', time() - 42000, $params["path"], $params["domain"], $params["secure"], $params["httponly"] ); } // Finally, destroy the session. session_destroy(); ?>
<?php // Initialize the session. // If you are using session_name("something"), don't forget it now! session_start(); // Unset all of the session variables. $_SESSION = array(); // If it desired to kill the session, also delete the session cookie. // Note: This will destroy the session, and not just the session data! if (ini_get("session.use_cookies")) { $params = session_get_cookie_params(); setcookie(session_name(), '', time() - 42000, $params["path"], $params["domain"], $params["secure"], $params["httponly"] ); } // Finally, destroy the session. session_destroy(); ?>
-,
session_start(); unset($_SESSION["nome"]); // where $_SESSION["nome"] is your own variable. if you do not have one use only this as follow **session_unset();**
. (, , , $_SESSION['user'] = $userModel;, unset($_SESSION['user']);). cookie (, ), :
$_SESSION['user'] = $userModel;
unset($_SESSION['user']);
setcookie(session_id(), "", time() - 3600);
Example #1 session_destroy() .
Example #1
session_destroy()
-: unset(). , $_SESSION ['user_id'], : unset ($ _ SESSION ['user_id'])
unset() cookie vars
Secondly: do we have code?
if you use session id. then you can do it
session_start(); unset($_SESSION['id']); session_destroy();
for cookies, you can set the cookie time to some past date.
Use only session_unset () for old legacy code that is not used by $ _SESSION.
session_start ();
session_unset ($ _ SESSION ['user email address']); session_destroy (); `
Source: https://habr.com/ru/post/1539098/More articles:C ++ Win32 Static Control Transparent Background - c ++цвет фона элемента управления (winapi) - background-colorhttps://translate.googleusercontent.com/translate_c?depth=1&pto=aue&rurl=translate.google.com&sl=ru&sp=nmt4&tl=en&u=https://fooobar.com/questions/1539095/super-keyword-without-extends-to-the-super-class&usg=ALkJrhhW8L2al6K09y0HZ16TYPzk7y63CgNetbeans code completion full class + namespace VS "use" - idesession_destroy () does not work - phpChecking bcrypt passwords always fails. Phalcon php - phpHow to change an unmodifiable list in java - javaError "DTD denied" when accessing the sharepoint 2013 / office365 list (but not openly aware of the use of XML) - listPagination with AWS DynamoDB with PHP - phpIs .NET AesManaged cryptography hardware accelerated? - .netAll Articles