小编Pac*_*tti的帖子

PHP中的局部变量覆盖会话变量

嗨,我在PHP页面遇到了一些问题:我正在使用教程编写一个小CMS .我设法写一个我用来与菜单交互的类,一切都运行良好:我可以在一个页面中插入,删除和获取菜单的所有项目,我可以重新排序它们.当我开始为用户编写相同的页面时,我遇到了一个问题:我正在使用Sentry类来验证每个页面中的用户:

require_once('../includes/Sentry.php');  
$theSentry = new Sentry();  
if (!$theSentry->checkLogin(1) ){ header("Location: index.php"); die(); }
Run Code Online (Sandbox Code Playgroud)

现在:如果我单独使用此验证,页面运行良好,但我需要查询数据库并提取user_admin.php页面中的所有用户:

require_once('../includes/DbUser.php');
$user_connector = new DbUser();
$all_users = array();
$all_users = $user_connector->getUserArray();
foreach($all_users as $id => $user){ echo " ... " };
Run Code Online (Sandbox Code Playgroud)

如果我评论这两个部分中的一部分,一切都运行良好,但是如果我让这个代码一起运行,页面就会正确创建,但下次我使用Sentry类运行一个页面时,我会被重定向到登录页面错误.Sentry类使用Validator类来检查凭据,此类中的方法报告数组输入而不是单个值输入.

我的问题是:如何可能从两个不同的类创建两个不同的对象,可以交互产生这样的问题?我想你需要两种方法的代码:

class Sentry {

...

function checkLogin($group=9,$user='',$pass='',$goodRedirect='',$badRedirect='') {
        // Include database and validation classes, and create objects
        require_once('DbConnector.php');
        require_once('Validator.php');
        $validate = new Validator();
        $loginConnector = new DbConnector();

        // If user is already logged in then check credentials
        if ($_SESSION['user'] && $_SESSION['pass']){ …
Run Code Online (Sandbox Code Playgroud)

php mysql object

3
推荐指数
1
解决办法
1602
查看次数

标签 统计

mysql ×1

object ×1

php ×1