简体   繁体   English

如何确保用户类型=“ admin”只能访问某个网页? PHP的MySQL

[英]How to make sure user type=“admin” can only access a certain webpage? php mysql

How do I make sure that only users with type="admin" can access for example admin.php 如何确保只有类型为“ admin”的用户才能访问例如admin.php

for example. 例如。 I am logged out. 我已注销。 but i can still access the admin.php, how to I make sure i can only access the page when i am logged in as an admin? 但是我仍然可以访问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");
        }
    }
}

Thank you so much. 非常感谢。

The simplest solution is 最简单的解决方案是

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

And the on your admin.php file: 并在您的admin.php文件上:

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

    print 'hi admin!';

}

However this is a 'basic' version, and I would suggest looking up PHP security, and looking up the users logged in ID with a table within your database to properly check the users logged in credentials. 但是,这是一个“基本”版本,我建议您查找PHP安全性,并使用数据库中的表查找登录ID的用户,以正确检查登录凭据的用户。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何通过php访问Python会话,以确保用户已通过身份验证并登录? - How can I access Python session by php to make sure that the user is authenticated and logged in? 如何只允许一天中的某些时间访问网页? - How can I only allow access to webpage at certain times of day? 如何确保用户仅在我的网页上单击过一次类似“赞”按钮的内容 - how to make sure a user only clicks on something once on my webpage like a “like” button 如何使只有管理员或管理员用户类型的用户才能看到导航链接 - How Do I make it where only an Admin or a Manager User type can see a Navigation Link PHP 确保仅从某个服务器调用文件 - PHP make sure that a file is called only from a certain server 如何在php中对网页进行ping操作,以确保其仍然有效? - How do I ping a webpage in php to make sure it's alive? 无法在 PHP 网页中进行 MySQL 查询 - Can't make MySQL queries in PHP webpage 如何确保codeigniter中的每个事件只能通过role_id查看(只有超级管理员可以查看所有列表)? - How to make sure every event only can be view by role_id (only super admin can see all the list) in codeigniter? PHP:我想在我的网页中有一个管理区域,以便如何在PHP中设置管理区域 - PHP: I want to have an Admin Area in my Webpage so how can I make my Admin area in PHP 如何确保 MySQL 中的值在 PHP 中保持其类型? - How do I make sure that values from MySQL keep their type in PHP?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM