简体   繁体   中英

how to logout admin or user php

I have two login forms, for user and admin.

When the User or Admin Login, I have set $_SESSION['login'] = true for user; $_SESSION['loginadmin'] = true for admin.I want to logout from page admin to use session_destroy and page user is logout too,

What could I do to logout admin and let user stay logged in

Simply set admin value to false

$_SESSION['loginadmin'] = false;

or you can unset admin variable only

unset($_SESSION['loginadmin']);

Hope this works.

Creating New Session

<?php 
session_start();
/*session is started if you don't write this line can't use $_Session  global variable*/
$_SESSION["newsession"]=$value;
?>

Getting Session

<?php 
session_start();
/*session is started if you don't write this line can't use $_Session  global variable*/
$_SESSION["newsession"]=$value;
/*session created*/
echo $_SESSION["newsession"];
/*session was getting*/
?>

Updating Session

<?php 
session_start();
/*session is started if you don't write this line can't use $_Session  
global variable*/
$_SESSION["newsession"]=$value;
/*it is my new session*/
$_SESSION["newsession"]=$updatedvalue;
/*session updated*/
?>

Deleting Session

<?php 
session_start();
/*session is started if you don't write this line can't use $_Session  
global variable*/
$_SESSION["newsession"]=$value;
unset($_SESSION["newsession"]);
/*session deleted. if you try using this you've got an error*/
?>

Check Out: https://www.w3schools.com/php/php_sessions.asp

http://php.net/manual/en/book.session.php

They have good information to fall back on and search for queries.

只需取消会话变量即可。
unset($_SESSION["loginadmin"]);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM