实际上,我在mysql数据库中有两个表1)admin 2)jusers。我想要的是当管理员使用他的电子邮件和密码登录时,他重定向到super_admin页面,类似用户使用电子邮件和密码登录,他重定向到admin_user页面。一切正常,我使用两个会话进行两次登录,问题是当我以用户身份退出时,它也会破坏管理会话..
<?php
session_start();
require_once 'class.user.php';
$user_login = new USER();
if($user_login->is_logged_in()!="")
{
$user_login->redirect('admin_user.php');
}
if(isset($_POST['btn-login']))
{
$email = trim($_POST['txtemail']);
$upass = trim($_POST['txtupass']);
$stmt = $user_login->runQuery("SELECT * FROM jusers WHERE jemail=:email_id");
$stmt->execute(array(":email_id"=>$email));
$userRow=$stmt->fetch(PDO::FETCH_ASSOC);
if($stmt->rowCount() == 1)
{
if($userRow['jpass']==md5($upass))
{
$_SESSION['user']['login'] = $userRow['juid'];
header("Location: admin_user.php");
}
admin_login的代码
<?php
session_start();
require_once 'class.user.php';
$admin_login = new USER();
if($admin_login->logged_in()!="")
{
$admin_login->redirect('super_admin.php');
}
if(isset($_POST['btn-adlogin']))
{
$email = trim($_POST['txtemail']);
$upass = trim($_POST['txtupass']);
$stmt = $admin_login->runQuery("SELECT * FROM admin WHERE email=:email_id");
$stmt->execute(array(":email_id"=>$email));
$userRow=$stmt->fetch(PDO::FETCH_ASSOC);
if($stmt->rowCount() == 1)
{
if($userRow['pass']==md5($upass))
{
$_SESSION['admin']['login'] = $userRow['auid'];
header("Location: super_admin.php");
}
记录的方法
public function is_logged_in()
{
if(isset($_SESSION['user']['login']))
{
return true;
}
}
public function logged_in()
{
if(isset($_SESSION['admin']['login']))
{
return true;
}
}
破坏方法
public function logout()
{
session_destroy();
$_SESSION['user']['login'] = false;
}
public function admin_logout()
{
session_destroy();
$_SESSION['admin']['login'] = false;
}
注销用户
<?php
session_start();
require_once 'class.user.php';
$user = new USER();
if(!$user->is_logged_in())
{
$user->redirect('login.php');
}
if($user->is_logged_in()!="")
{
$user->logout();
$user->redirect('login.php');
}
?>
退出管理员
<?php
session_start();
require_once 'class.user.php';
$admin_user = new USER();
if(!$admin_user->logged_in())
{
$admin_user->redirect('admin_login.php');
}
if($admin_user->logged_in()!="")
{
$admin_user->admin_logout();
$admin_user->redirect('admin_login.php');
}
?>
这是什么错误?
帮帮我......
答案 0 :(得分:0)
session_destroy
基本上从$ _SESSION删除所有内容,根据需要可能更容易unset($_SESSION['admin'])
或unset($_SESSION['user'])
。
答案 1 :(得分:-1)
只是因为没有必要而删除我的答案。因为它已经回答了。