2016-09-30 39 views
0

所以,目前,我正在为一个论坛的mod面板工作。数据库中有一个名为“管理员”的变量。默认值为0,但我希望能够将其设置为'1',然后人们可以访问页面。目前我一直在寻找类似下面:如果mysql变量是'1',我将如何使页面仅可访问?

<?php 
include('config.php'); 
    if(isset($_SESSION['moderator']) and $_SESSION['moderator']) { 
    } else { 
    header("location:noaccess.php"); 
} 
?> 

不过,我想不出一个跟你说如果是1,则允许访问它不工作。这是config.php的重点。 '*'=删除了信息

<?php 
/****************************************************** 
------------------Required Configuration--------------- 
Please edit the following variables so the forum can 
work correctly. 
******************************************************/ 

//We log to the DataBase 
mysql_connect('*', '*', '*'); 
mysql_select_db('forum_database'); 

//Username of the Administrator 
$admin='The_Darthonian'; // For admin forum features 

/****************************************************** 
-----------------Optional Configuration---------------- 
******************************************************/ 

//Forum Home Page 
$url_home = 'index.php'; 

//Design Name 
$design = 'default'; 


/****************************************************** 
----------------------Initialization------------------- 
******************************************************/ 
include('init.php'); 
?> 

感谢

+0

为什么不测试文件的存在? – trincot

+0

'if(condition == 1){...} else {...}'是基本逻辑。阅读关于php.net的会话http://php.net/manual/en/reserved.variables.session.php –

回答

0

翻转你的逻辑......

<?php 
include 'config.php'; 

if(empty($_SESSION['moderator'])) { 
    // $_SESSION['moderator'] is not set or 0 
    header("Location:noaccess.php"); 
    exit; 
} 

// $_SESSION['moderator'] is set and something other than 0, 
// the following page is moderator only... 
相关问题