如何确保用户type =“admin”只能访问某个网页? php mysql

时间:2014-07-31 14:51:17

标签: php session login admin

如何确保只有type =“admin”的用户可以访问例如admin.php

例如,

。我退出了。但我仍然可以访问admin.php,如何确保我只能在以管理员身份登录时访问该页面?

if($count==1){

// Register $myusername, $mypassword and redirect to file "login_success.php"


    while($row = mysql_fetch_array($result)){
        //remove this line ******header("location:customer_home.php");
        if($row['type'] == 'admin'){
            header("location: admin.php");
        } else if($row['type'] == 'customer'){
            header("location: customer_home.php");
        }
    }
}

非常感谢你。

1 个答案:

答案 0 :(得分:0)

最简单的解决方案是

if($row['type'] == 'admin'){
    $_SESSION['isAdmin'] = true;
        header("location: admin.php");
    }

在你的admin.php文件上:

if($_SESSION['isAdmin']==true){

    print 'hi admin!';

}

然而,这是一个“基本”版本,我建议查找PHP安全性,并使用数据库中的表查找登录ID的用户,以正确检查登录凭据的用户。