[英]Logged in user redirect depending on column values PHP
I have a script below which redirects non logged in users to the logout page, which works ok for users not logged in. The table this accesses is called 'users'. 我下面有一个脚本,用于将未登录的用户重定向到注销页面,该脚本对于未登录的用户可以正常使用。此访问的表称为“用户”。
What I am trying to do however, is redirect logged in users whose data in the 'users_type' does not match the query below. 但是,我要尝试的是重定向登录的用户,这些用户的“ users_type”中的数据与下面的查询不匹配。 For instance, if their 'users_type' data is 'Admin', it will redirect the page to the logout area. 例如,如果他们的“ users_type”数据是“ Admin”,它将页面重定向到注销区域。 Any ideas? 有任何想法吗?
<?php
require_once ('config.inc.php');
$page_title = 'Page Title';
include ('header.html');
if (!isset($_SESSION['users_type']) == 'Sales') {
$url = 'http://' . $_SERVER['HTTP_HOST']
. dirname($_SERVER['PHP_SELF']);
if ((substr($url, -1) == '/') OR (substr($url, -1) == '\\') ) {
$url = substr ($url, 0, -1);
}
$url .= 'logout.php';
ob_end_clean();
header("Location: $url");
exit();
}
?>
EDIT: This code works 编辑:此代码有效
<?php
require_once ('config.inc.php');
$page_title = 'Page Title';
include ('header.html');
if(isset($_SESSION['users_type']) && $_SESSION['users_type'] != 'Sales') {
$url = 'http://' . $_SERVER['HTTP_HOST']
. dirname($_SERVER['PHP_SELF']);
if ((substr($url, -1) == '/') OR (substr($url, -1) == '\\') ) {
$url = substr ($url, 0, -1);
}
$url .= 'logout.php';
ob_end_clean();
header("Location: $url");
exit();
}
?>
Change 更改
if (!isset($_SESSION['users_type']) == 'Sales')
To 至
if (isset($_SESSION['users_type']) && $_SESSION['users_type'] == 'Sales')
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.