August 1, 201115 yr I've created a login where members of staff (from specific companies) login with a general company username and password, then register for a personal account. After they have submitted the reg form, I need to kill the session (or log them out of company login) and redirect to the login page, where they can login using their new personal login details. What's the best way to do this? Should I kill the session when the login page loads? Sorry if this is basic, I'm quite new to PHP. Thanks guys Edited August 1, 201115 yr by drennan
August 1, 201115 yr I've created a login where members of staff (from specific companies) login with a general company username and password, then register for a personal account. After they have submitted the reg form, I need to kill the session (or log them out of company login) and redirect to the login page, where they can login using their new personal login details. What's the best way to do this? Should I kill the session when the login page loads? Sorry if this is basic, I'm quite new to PHP. Thanks guys Create a logout page, and enter: session_destroy();
August 1, 201115 yr Author Thanks but didn't work. I've put <?php session_destroy(); ?> at the start of my thanks page but if I navigate back to the register page after the thanks page loads, it is still displaying the username they are logged in as.
August 1, 201115 yr Thanks but didn't work. I've put <?php session_destroy(); ?> at the start of my thanks page but if I navigate back to the register page after the thanks page loads, it is still displaying the username they are logged in as. What sessions are being set? PHP Sessions Or Cookie sessions?
August 1, 201115 yr Author Sorry mate not sure - using DW CS5 panels to do most of my PHP. Can you see that from here? <?php if (!isset($_SESSION)) { session_start(); } $MM_authorizedUsers = ""; $MM_donotCheckaccess = "true"; function isAuthorized($strUsers, $strGroups, $UserName, $UserGroup) { $isValid = False; if (!empty($UserName)) { $arrUsers = Explode(",", $strUsers); $arrGroups = Explode(",", $strGroups); if (in_array($UserName, $arrUsers)) { $isValid = true; } if (in_array($UserGroup, $arrGroups)) { $isValid = true; } if (($strUsers == "") && true) { $isValid = true; } } return $isValid; } $MM_restrictGoTo = "index.php"; if (!((isset($_SESSION['MM_Username'])) && (isAuthorized("",$MM_authorizedUsers, $_SESSION['MM_Username'], $_SESSION['MM_UserGroup'])))) { $MM_qsChar = "?"; $MM_referrer = $_SERVER['PHP_SELF']; if (strpos($MM_restrictGoTo, "?")) $MM_qsChar = "&"; if (isset($_SERVER['QUERY_STRING']) && strlen($_SERVER['QUERY_STRING']) > 0) $MM_referrer .= "?" . $_SERVER['QUERY_STRING']; $MM_restrictGoTo = $MM_restrictGoTo. $MM_qsChar . "accesscheck=" . urlencode($MM_referrer); header("Location: ". $MM_restrictGoTo); exit; } ?>
August 1, 201115 yr Sorry mate not sure - using DW CS5 panels to do most of my PHP. Can you see that from here? <?php if (!isset($_SESSION)) { session_start(); } $MM_authorizedUsers = ""; $MM_donotCheckaccess = "true"; function isAuthorized($strUsers, $strGroups, $UserName, $UserGroup) { $isValid = False; if (!empty($UserName)) { $arrUsers = Explode(",", $strUsers); $arrGroups = Explode(",", $strGroups); if (in_array($UserName, $arrUsers)) { $isValid = true; } if (in_array($UserGroup, $arrGroups)) { $isValid = true; } if (($strUsers == "") && true) { $isValid = true; } } return $isValid; } $MM_restrictGoTo = "index.php"; if (!((isset($_SESSION['MM_Username'])) && (isAuthorized("",$MM_authorizedUsers, $_SESSION['MM_Username'], $_SESSION['MM_UserGroup'])))) { $MM_qsChar = "?"; $MM_referrer = $_SERVER['PHP_SELF']; if (strpos($MM_restrictGoTo, "?")) $MM_qsChar = "&"; if (isset($_SERVER['QUERY_STRING']) && strlen($_SERVER['QUERY_STRING']) > 0) $MM_referrer .= "?" . $_SERVER['QUERY_STRING']; $MM_restrictGoTo = $MM_restrictGoTo. $MM_qsChar . "accesscheck=" . urlencode($MM_referrer); header("Location: ". $MM_restrictGoTo); exit; } ?> Ok, Create a page called logout.php place <?php session_destroy(); ?> go to it, and try reaccess the members area..
August 5, 201115 yr Perfect, thanks mate your logout page should more or less be in the format of this instead if(isset($_SESSION['uid'])){ session_destroy(); header('Location:index.php'); exit; }else{ exit('You are already logged out'); } Edited August 5, 201115 yr by webdesigner93
Create an account or sign in to comment