1

首先,我的英语不太好。

你好,我的项目有问题

我创建了一个网站,允许您从前端(作为成员)和管理员登录。我使用不同的用户名和密码登录(前端和后端),但是一旦我从后端注销,前端也会注销。

我认为这是因为我运行了session_destroy()脚本,它破坏了包括前端会话在内的所有会话。

Zend Framework我尝试使用and Joomlawith来搜索这个PHP

4

2 回答 2

0

我想这是您以以下身份登录时的会话admin

$_SESSION['user']['id'] = 1;
$_SESSION['user']['group'] = 'admin';
...

但是,当您只是一个时,这是您的会话user

$_SESSION['user']['id'] = 99;

无论您logout.php位于何处,请执行以下类似操作:

if ($_SESSION['user']['group'] == 'admin')
    $_SESSION['user']['group'] = null;
else
    destroy_session();

我希望你明白了!

更新

这可能有效:

/* Do NOT unset the $_SESSION['user']['role'] */

if ($_SESSION['user']['role'] == 'user') {

    /* For Users */
    $_SESSION['user']['login'] = false;
    $_SESSION['user']['id'] = null;
    $_SESSION['user']['last-visit'] = null;
    $_SESSION['user']['ip'] = null;
}

if ($_SESSION['user']['role'] == 'admin') {

    /* Unset Admin Specific Variables */
    $_SESSION['admin']['login'] = false;
    $_SESSION['admin']['id'] = null;
    $_SESSION['admin']['last-visit'] = null;
    $_SESSION['admin']['ip'] = null;
}

/* Get rid of session_destroy() */
// session_destroy();

顺便说一句,您只是手动重置变量,这在某种程度上等于完全销毁会话,但仍然保持会话对另一方有效。

更好

/* Assign the `user_id` to the session, when you log in ... */
/* login.php */

$_SESSION[$user_id] = array();

/* Now fill-up the new array with data ... */
$_SESSION[$user_id]['role'] = 'admin';
$_SESSION[$user_id]['login'] = true;

/* When you want to Log out, just simply null the array based on the user_id again */
/* logout.php */

$_SESSION[$user_id] = null;

/* Here you go, as long as you have different user_id in your database, 
   you have separated sessions! */
于 2013-04-11T05:52:55.850 回答
0

您应该为不同的会话创建不同的变量..

以下是一些可能会派上用场的示例。

<?php 
 // you have to open the session to be able to modify or remove it 
 session_start(); 

 // to change a variable, just overwrite it 
 $_SESSION['size']='large'; 

 //you can remove a single variable in the session 
 unset($_SESSION['shape']); 

 // or this would remove all the variables in the session, but not the session itself 
 session_unset(); 

 // this would destroy the session variables 
 session_destroy(); 
 ?> 

希望能帮助到你..

于 2013-04-11T05:22:10.750 回答