Skip to content
View in the app

A better way to browse. Learn more.

Web Designer Forum

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Logout user/kill session on page load?

Featured Replies

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 by drennan

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();

  • 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.

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?

  • 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;

}

?>

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..

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 by webdesigner93

Create an account or sign in to comment

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.