php/mysql-基于user_level重定向时出现的问题 [英] php / mysql - Issue when redirecting based on user_level
问题描述
我目前正在基于user_level构建一个控制面板.如果用户的权限为(0),则除了索引页面外,他们无法访问其他任何内容,而级别(1)则可以访问所有内容.
I'm currently building a control panel based on user_level. If a user has level (0) they can't access anything besides the index page, level (1) can access everything.
我的问题是,使用我当前使用的代码...即使将user_level设置为0以上,它也只能将我重定向回索引页面.
My problem is, with the current code I am using... It only redirects me back to the index page, even if I set my user_level above 0.
代码:
<?php
$db_connection = new mysqli(DB_HOST, DB_USER, DB_PASS, DB_NAME);
require_once("config/db.php");
$page_rows = results_per_page;
if (!$db_connection->set_charset("utf8")) {
$db_connection->errors[] = $db_connection->error;
}
if($_SESSION["user_level"] == 0)
{
header('Location: index.php');
}
?>
如果我尝试使用以下代码......
and If I try using the following code....
<?php
$db_connection = new mysqli(DB_HOST, DB_USER, DB_PASS, DB_NAME);
require_once("config/db.php");
$page_rows = results_per_page;
if (!$db_connection->set_charset("utf8")) {
$db_connection->errors[] = $db_connection->error;
}
if($_SESSION["user_level"] == 0) {
header('Location: index.php');
} else {
header('Location: download.php');
?>
在download.php页面上显示 HTTP错误500 .
I get HTTP ERROR 500 on the download.php page.
感谢所有帮助. (对不起,"Noob"的错误,这是我的第一个更大的项目.)
All help is appreciated. (Sorry for any 'Noob' mistakes, This is my first bigger project).
推荐答案
您正在使用session
,如:
if($_SESSION["user_level"] == 0)
{
header('Location: index.php');
}
,但会话未在此处开始.在第一行开始会话,如:
but session is not started here. Start the session on first line like:
session_start();
只有在此之后,您才能访问会话变量.
only after that you can access the session variable.
这篇关于php/mysql-基于user_level重定向时出现的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!