如果使用php在同一浏览器上创建了新会话,则注销用户


logging out the user if new session is created on the same browser using php

我有一个具有多个用户级别的系统,当一个用户登录,然后在同一浏览器上登录另一个用户时,我想登录现有用户。我不知道该怎么走。。这是我的代码:

ob_start();
session_start();
require_once('../db/db_connection.php');
$user_session=$_SESSION['username'];
$user_s_q=mysql_query("select userlevel from users where  username='$user_session'");
$se_row=mysql_fetch_array($user_s_q);
    $level=$se_row['userlevel'];

if(empty($_SESSION['username'])&& empty($_SESSION['userLevel'])){
    header("location:../index.php");
    }
    elseif($level!='admin'){
        header("location:../index.php");
        }
   elseif($level>1){
       //logout the existing user
      }
    else{
       //display content
          }

我该怎么做?有什么帮助吗?

您将想要销毁旧会话:

session_regenerate_id(TRUE);
$_SESSION=array();

或者使用php手册中的示例进行session_delete(http://php.net/manual/en/function.session-destroy.php)