Hướng dẫn what are the different user levels in accessing a website php? - các cấp độ người dùng khác nhau trong việc truy cập một trang web php là gì?

Các danh mục khác nhau của người dùng truy cập một trang web tại bất kỳ thời điểm nào. Tuy nhiên, một số trang trong một trang web có nghĩa là được truy cập bởi người dùng cụ thể.

Chẳng hạn, các trang web được quản trị viên hệ thống truy cập có thể không giống như các trang có thể truy cập được cho người dùng chung.

Khi triển khai các trang web quan trọng cho các tổ chức tài chính, cũng như các chính phủ khác, việc bảo vệ các trang cụ thể là cần thiết.

Điều quan trọng là bảo vệ một số trang web nhất định để kiểm soát quyền truy cập của người dùng. Bài viết này sẽ giúp người học hiểu cách giới hạn quyền truy cập vào một số trang web nhất định trong PHP.

Điều kiện tiên quyết

Để có được nhiều hơn từ hướng dẫn này, bạn sẽ cần:

  • Kiến thức cơ bản về HTML, CSS và PHP.
  • Một biên tập viên như Visual Studio Code hoặc bất kỳ thứ nào khác mà bạn thích.
  • XAMPP.
  • Bootstrap 5

Bước 1 - Tạo thư mục dự án

Trên máy tính của bạn, tìm kiếm một thư mục có tên XAMPP trong phân vùng gốc của bạn (giả sử bạn đã cài đặt XAMPP).

Mở thư mục này sau đó duyệt và xác định vị trí một thư mục khác được gọi là HTDDOCS. Bên trong HTDOCS, hãy tạo một thư mục khác và thêm tên dự án của bạn. Trong hướng dẫn này, tôi đặt tên cho cửa hàng trái cây.

Hướng dẫn what are the different user levels in accessing a website php? - các cấp độ người dùng khác nhau trong việc truy cập một trang web php là gì?

Bên trong cửa hàng trái cây, tạo một thư mục khác và đặt tên cho nó CSS. Bên trong CSS, chèn tệp bootstrap bạn đã tải xuống.

Hướng dẫn what are the different user levels in accessing a website php? - các cấp độ người dùng khác nhau trong việc truy cập một trang web php là gì?

Bước 2 - Đảm bảo rằng XAMPP đang hoạt động chính xác

Bấm đúp vào ứng dụng XAMPP và bắt đầu các dịch vụ Apache và MySQL. Đảm bảo rằng các dịch vụ này đang chạy bình thường mà không có bất kỳ lỗi nào.

Hướng dẫn what are the different user levels in accessing a website php? - các cấp độ người dùng khác nhau trong việc truy cập một trang web php là gì?

Bước 3 - Mở thư mục dự án trong trình soạn thảo của bạn

Bây giờ chúng tôi có thể mở thư mục dự án trong trình chỉnh sửa mã như mã vs

Hướng dẫn what are the different user levels in accessing a website php? - các cấp độ người dùng khác nhau trong việc truy cập một trang web php là gì?

Bước 4 - Tạo trang chủ

Trong thư mục gốc của bạn, hãy tạo một tệp mới có tên Home.php: Thêm mã sau vào tệp được tạo:

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width,initial-scale=1.0">
    <title>home page</title>
    <link rel="icon" type="image/x-icon" href="images/logo.jfif">
    <link rel="stylesheet" type="text/css" href="css/bootstrap.min.css">
</head>

<body>
    <?php include 'nav.php'?>
    <div class="container justify-content-center">
        h3 class="text-center">welcome to our fruit store</h3>
        <h2 class="text-center">we deliver fruits to your doorstep</h2>
    </div>

    <div class="container justify-content-center">
        <div class="row">
            <div class="col-sm-3 m-2 card border-black shadow-lg" style="width:300px">
                <img class="card-img-top" src="images/apple.jpg" alt="Card image">
                <div class="card-body">
                    <h4 class="card-title">Apple</h4>
                    <p class="card-text">Price: $0.5</p>
                    <a href="#" class="btn btn-primary">Order</a>
                </div>
            </div>

            <div class="col-sm-3 m-2 card border-black shadow-lg" style="width:300px">

                <img class="card-img-top" src="images/banana.jpg" alt="Card image">
                <div class="card-body">
                    <h4 class="card-title">Banana</h4>
                    <p class="card-text">Price: $0.3</p>
                    <a href="#" class="btn btn-primary">Order</a>
                </div>
            </div>

            <div class="col-sm-3 m-2 card border-black shadow-lg" style="width:300px">
                <img class="card-img-top" src="images/grape.jpg" alt="Card image">
                <div class="card-body">
                    <h4 class="card-title">Grapes</h4>
                    <p class="card-text">Price: $2.5</p>
                    <a href="#" class="btn btn-primary">Order</a>
                </div>

            </div>

            <div class="col-sm-3 m-2 card border-black shadow-lg" style="width:300px">
                <img class="card-img-top" src="images/strawberry.jpg" alt="Card image">
                <div class="card-body">
                    <h4 class="card-title">Strawberry</h4>
                    <p class="card-text">Price: $5.5</p>
                    <a href="#" class="btn btn-primary">Order</a>
                </div>

            </div>

        </div>

</body>

</html>

Bước 5 - Tạo trang liên hệ

Tạo tệp Contact.php và sau đó thêm mã sau:

<?php 
include 'protect.php';
?>

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Contact us</title>
    <link rel="icon" type="image/x-icon" href="images/logo.jfif">
    <link rel="stylesheet" type="text/css" href="css/bootstrap.min.css">
</head>

<body>
    <?php include 'nav.php'?>
    <div class="container justify-content-center">
        <div class="row d-flex">
            <div class="col-sm-4">
                <form action="">
                    <h2>send us a massage</h2>
                    <div class="form-group">
                        <label>Name</label>
                        <input type="text" class="form-control mb-4" placeholder="text">
                    </div>
                    <div class="form-group">
                        <label>Subject</label>
                        <input type="text" class="form-control mb-4" placeholder="subject">
                    </div>
                    <div class="form-group">
                        <label>Subject details</label>
                        <input type="text" class="form-control mb-4" placeholder="subject details">
                    </div>
                    <button>submit</button>
                </form>
            </div>
        </div>
    </div>
</body>
</html>

Bước 6 - Tạo trang Giới thiệu

Tạo một tệp mới được đặt tên là about.php sau đó thêm mã sau:

<?php 
include 'protect.php'
?>

<!DOCTYPE html>

<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width,initial-scale=1.0">
    <title>About us</title>
    <link rel="icon" type="image/x-icon" href="images/logo.jfif">
    <link rel="stylesheet" type="text/css" href="css/bootstrap.min.css">
</head>

<body>

    <?php include 'nav.php'?>
    <h2 class="text-center">about fruits vendor Ltd</h2>
    <div class="col-sm-9 text-center">
        <p>Lorem ipsum dolor sit amet consectetur adipisicing elit.Iste quas provident dolorum! Voluptate totam illum
            eum! Fugiat corrupti sint perspiciatis minus neque, cupiditate aperiam
            saepe quisquam asperiores illum itaque autem!</p>
        <p>Lorem ipsum dolor sit amet consectetur adipisicing elit.Possimus quas minus autem tenetur neque quos ut sunt
            aliquid
            reprehenderit magni nostrum, dolor culpa dolorum deleniti quidem libero pariatur quam explicabo!
        </p>
    </div>
</body>

</html>

Bước 7 - Tạo mẫu đăng ký

Mẫu đăng ký sẽ được sử dụng để lưu trữ thông tin của người dùng trong cơ sở dữ liệu. Thông tin này được sử dụng khi người dùng muốn đăng nhập vào hệ thống. Tạo một tệp mới và đặt tên nó đăng ký.php.

Đảm bảo rằng hành động biểu mẫu trỏ đến hành động trong cùng một tệp, tức là, đăng ký.php và phương thức biểu mẫu được đăng vì đây là một cách an toàn để gửi dữ liệu.

Trong các mục biểu mẫu, đảm bảo mỗi mục có một tên. Nó sẽ hữu ích khi truy cập cơ sở dữ liệu.

Thêm mã bên dưới vào tệp đăng ký.php của bạn:

<?PHP
if(isset($_REQUEST["name"]))

{
$name = $_REQUEST["name"];
$email= $_REQUEST["email"];
$phone = $_REQUEST["phone"];
$password = $_REQUEST["password"];
$password = password_hash($password, PASSWORD_BCRYPT);
include 'connect.php';

  $sql = "INSERT INTO `clients`(`id`, `name`, `email`,
`phone`, `password`) VALUES
(null,'$name','$email','$phone','$password')";
  mysqli_query($con,$sql) or die(mysqli_error($con));
  header("location:home.php");
  }
?>
<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Register</title>
    <link rel="icon" type="image/x-icon" href="images/logo.jfif">
    <link rel="stylesheet" type="text/css" href="css/bootstrap.min.css">
</head>

<body>

    <?php include 'nav.php'?>

    <div class="container">
        <div class="row justify-content-center">
            <div class="col-sm-6 border shadow-lg">
                <form action="register.php" method="post" class="mb-5 mt-5 rounded-top rounded-bottom form-group">

                    <div class="mt-5 mb-5 flex-column text-center">
                        <div class="mx-auto d-block">
                            <img src="images/logo.jfif" alt="Logo" style="width: 80px;" class="rounded-pill">
                            <h3>Fruits vendors Ltd</h3>
                        </div>
                        <h4>Registration form</h4>
                    </div>

                    <div class="form-group">
                        <label>Enter Your Name</label>
                        <input type="text" class="form-control mb-4" placeholder="name" name="name" required>
                    </div>
                    <div class="form-group">
                        <label>Enter Your Email</label>
                        <input type="email" class="form-control mb-4" placeholder="email" name="email" required>
                    </div>
                    <div class="form-group">
                        <label>Enter Your Phone Number</label>
                        <input type="tel" class="form-control mb-4" placeholder="phone" name="phone" required>
                    </div>
                    <div class="form-group">
                        <label>Set Password</label>
                        <input type="password" class="form-control mb-4" placeholder="password" name="password" required>
                    </div>
                    <button class="btn btn-block col-sm-4 btn-outline-info btn-control">register</button>
                </form>
            </div>
        </div>
    </div>
</body>

</html>

Bước 8 - Tạo cơ sở dữ liệu

Trên trình duyệt của bạn gõ localhost và điều hướng đến phpmyadmin. Tiếp theo, nhấp vào Mới sau đó nhập tên cơ sở dữ liệu, tức là, Fruits-Store, sau đó tạo.

Hướng dẫn what are the different user levels in accessing a website php? - các cấp độ người dùng khác nhau trong việc truy cập một trang web php là gì?

Bên trong cơ sở dữ liệu này, tạo một bảng và đặt tên cho nó là máy khách. Nó nên có các trường sau:

Id - (type INT, primary key),
name - (type CHAR, size 50),
email - (type VARCHAR, size 50),
phone - (type VARCHAR, size 30)
password - (type VARCHAR, size 100)

Sau khi lưu bảng máy khách, chọn điện thoại và trường email và làm cho chúng độc đáo. Điều này được thực hiện để đảm bảo rằng cùng một email hoặc số điện thoại không thể thuộc về nhiều người dùng.

Hướng dẫn what are the different user levels in accessing a website php? - các cấp độ người dùng khác nhau trong việc truy cập một trang web php là gì?

Tạo kết nối cơ sở dữ liệu

Tạo một tệp PHP mới và đặt tên nó Connect.php. Tệp này sẽ giúp chúng tôi tiết kiệm thời gian bằng cách tránh lặp lại mã.

Tạo một biến có tên là Con sẽ được sử dụng để lưu trữ kết nối. Chúng tôi cũng sẽ sử dụng hàm mysqli_connect có bốn tham số, tức là tên của máy chủ, tên người dùng, mật khẩu và tên cơ sở dữ liệu.

<?php

  $con = mysqli_connect("localhost", "root", "",
"fruits-store") or die(mysqli_connect_error());

?>

Bước 9 - Tạo thanh điều hướng

Điều hướng đóng một vai trò rất quan trọng vì nó sẽ giúp xác định các trang sẽ hiển thị cho người dùng khác nhau.

Tạo một tệp mới và đặt tên cho nó là Nav.php. Tiếp theo, thêm mã sau trong tệp được tạo:

Bao gồm tệp này trong tất cả các trang, ngay sau khi thẻ cơ thể trong HTML của bạn.

<nav class="navbar navbar-expand-sm navbar-light bg-info p-2 mb-5">
    <div class="container-fluid">
        <a class="navbar-brand d-block mx-auto text-center" href="home.php">
            <img src="images/logo.jfif" alt="Logo" style="width:80px;" class="rounded-pill">
            <h4 class="vollkorn text-white">fruits vendor Ltd</h4>
        </a>
        <button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#mynavbar">
            <span class="navbar-toggler-icon"></span>
        </button>

        <div class="collapse navbar-collapse m-3" id="mynavbar">

            <ul class="navbar-nav ms-auto px-4">
                <li class="nav-item">
                    <a class="nav-link link-success" href="home.php">Home</a>
                </li>
                <li class="nav-item">
                    <a class="nav-link link-primary" href="contact.php">contact us</a>
                </li>
                <li class="nav-item">
                    <a class="nav-link link-primary" href="about.php">aboutus</a>
                </li>
                <li class="nav-item">
                    <a class="nav-link link-primary" href="register.php">Register</a>
                </li>

                <li class="nav-item">
                    <a class="nav-link link-primary" href="login.php">login.php</a>
                </li>
                <li class="nav-item">
                    <a class="nav-link link-primary" href="logout.php">logout</a>
                </li>
            </ul>
        </div>
    </div>
</nav>

Bước 10 - Tạo biểu mẫu đăng nhập

Trong bước này, bây giờ chúng tôi muốn thực hiện đăng nhập để nó được sử dụng để kiểm soát quyền truy cập của người dùng. Một số trang nhất định sẽ không thể truy cập được trước khi đăng nhập vào hệ thống trong khi những trang khác sẽ được hiển thị ngay cả trước khi đăng nhập vào hệ thống.

Để bắt đầu với biểu mẫu đăng nhập Dán mã sau vào tệp đăng nhập của bạn:

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>login</title>
    <link rel="icon" type="image/x-icon" href="images/logo.jfif">
    <link rel="stylesheet" type="text/css" href="css/bootstrap.min.css">
</head>

<body class="bg-light">
    <?php include 'nav.php'?>
    <div class="container">
        <div class="row justify-content-center">
            <div class="col-sm-6 border shadow-lg">
                <div class="mt-5 mb-5 flex-column text-center">
                    <div class="mx-auto d-block">
                        <img src="images/logo.jfif" alt="Logo" style="width: 80px;" class="rounded-pill">
                        <h3 class="vollkorn"> Fruits Vendor Ltd</h3>
                    </div>
                    <h4>Login</h4>

                </div>
                <form action="login.php" method="post" class="mb-5 mt-5 rounded-top rounded-bottom">
                    <div class="form-group">
                        <label>Enter Your Email</label>
                        <input type="email" class="form-control mb-4" placeholder="email" name="email" required>
                    </div>

                    <div class="form-group">
                        <label>Enter Your Password</label>
                        <input type="password" class="form-control mb-4" placeholder="password" name="password"
                            required>
                    </div>

                    <div class="container">
                        <div class="row justify-content-center">
                            <div class="col-sm-6">
                                <button class="btn btn-control btn-outline-info btn-block col-sm-4">login</button>
                            </div>
                            <div class="col-sm-6 d-flex">
                                <p class="float-right">Don't have an account? </p>
                                <a href="register.php" class="signin">register</a>

                            </div>
                        </div>
                    </div>
                </form>
            </div>
        </div>
    </div>
</body>

</html>

Bước 11 - Thực hiện chức năng đăng nhập

Bây giờ, hãy để thực hiện chức năng đăng nhập của mẫu đăng nhập sẽ tìm nạp chi tiết đăng nhập của người dùng từ cơ sở dữ liệu và xác minh xem nó có chính xác trước khi cho phép người dùng xem một số trang web nhất định hay không.

Tạo một tập tin và đặt tên cho nó đăng nhập.php. Trong tệp này, thêm mã bên dưới:

<?php
include 'connect.php';

 if(isset($_REQUEST["password"]))

{

$email = $_REQUEST["email"]; checking and retrieving email
$password = $_REQUEST["password"];

//retrieve one record that matches the email
//check the password hash
//store data in a session
//preparing the query so that hacking the database becomes difficult

$query = mysqli_prepare($con, "SELECT * FROM `clients` WHERE
email = ?");
mysqli_stmt_bind_param($query, "s", $email);
mysqli_stmt_execute($query);
$result = mysqli_stmt_get_result($query);

//checking number of rows that are stored in the result variable
if(mysqli_num_rows($result) == 1){ //counting number of rows in result
   $client = mysqli_fetch_assoc($result);
   $hash = $client["password"]; //retrieving the encrypted password

  if(password_verify($password, $hash)){ /*compare the password that the user provided and the hash password. If the passwords match then the user
can log in. If they do not match then an error message is displayed using
a cookie*/

//storing user information in a session

    session_start();
    $_SESSION["name"] = $customer["name"];
    $_SESSION["id"] = $customer["id"];
    $_SESSION["logged_in"] = true; 
    header("location:home.php");
      //success
  }else{
    //if the number of rows is not one then show this message
    setcookie("error", "wrong username or password", time()+3);
  }

}else{
  //if the password provided by user and hash do not match
  setcookie("error", "wrong username or password", time()+3);
}
}
?>

Đến thời điểm này, đăng nhập sẽ hoạt động hoàn hảo.

Tạo một tệp mới và tên dưới dạng bảo vệ.php. Tệp này kiểm tra xem phiên có tồn tại có nghĩa là người dùng đã đăng nhập không. Nếu phiên không tìm thấy tệp này sẽ chuyển hướng người dùng đến trang đăng nhập.

Tệp này cũng bảo vệ một số trang nhất định khỏi được người dùng trái phép truy cập. Trong trường hợp này, bạn không thể truy cập một trang nếu bạn không đăng nhập.

Thêm mã bên dưới trong tệp bảo vệ.php:

<?php

  session_start();

//checking if the session exists
//if the session is not set it redirects the user to the login form/page

  if(! isset($_SESSION["logged_in"])){
      header("location:login.php");
  }

?>

Khi chúng tôi muốn bảo vệ một trang, chúng tôi sẽ nhập/bao gồm tệp này khi bắt đầu tệp mà bạn muốn bảo vệ, như đã trình bày dưới đây:

<?php 
include 'protect.php';
?>

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Contact us</title>
    <link rel="icon" type="image/x-icon" href="images/logo.jfif">
    <link rel="stylesheet" type="text/css" href="css/bootstrap.min.css">
</head>

<body>
    <?php include 'nav.php'?>
    <div class="container justify-content-center">
        <div class="row d-flex">
            <div class="col-sm-4">
                <form action="">
                    <h2>send us a massage</h2>
                    <div class="form-group">
                        <label>Name</label>
                        <input type="text" class="form-control mb-4" placeholder="text">
                    </div>
                    <div class="form-group">
                        <label>Subject</label>
                        <input type="text" class="form-control mb-4" placeholder="subject">
                    </div>
                    <div class="form-group">
                        <label>Subject details</label>
                        <input type="text" class="form-control mb-4" placeholder="subject details">
                    </div>
                    <button>submit</button>
                </form>
            </div>
        </div>
    </div>
</body>
</html>
0

Bước 13 - Tạo trang đăng xuất

Tạo tệp đăng xuất.php và sau đó thêm mã sau:

<?php 
include 'protect.php';
?>

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Contact us</title>
    <link rel="icon" type="image/x-icon" href="images/logo.jfif">
    <link rel="stylesheet" type="text/css" href="css/bootstrap.min.css">
</head>

<body>
    <?php include 'nav.php'?>
    <div class="container justify-content-center">
        <div class="row d-flex">
            <div class="col-sm-4">
                <form action="">
                    <h2>send us a massage</h2>
                    <div class="form-group">
                        <label>Name</label>
                        <input type="text" class="form-control mb-4" placeholder="text">
                    </div>
                    <div class="form-group">
                        <label>Subject</label>
                        <input type="text" class="form-control mb-4" placeholder="subject">
                    </div>
                    <div class="form-group">
                        <label>Subject details</label>
                        <input type="text" class="form-control mb-4" placeholder="subject details">
                    </div>
                    <button>submit</button>
                </form>
            </div>
        </div>
    </div>
</body>
</html>
1

Bước 14 - Việc ẩn một số trang web nhất định

Chúng tôi cần bao gồm một câu lệnh IF trong tệp Nav.php của chúng tôi sẽ đảm bảo rằng người dùng không thể truy cập một số trang nhất định nếu chúng không đăng nhập.

Giả sử rằng bạn đã tạo tất cả các trang bạn cần cho trang web của mình, trong trường hợp của chúng tôi, chúng tôi có một nhà, đăng nhập, đăng nhập, đăng ký, liên hệ và về trang.

Chúng tôi muốn thực hiện đăng nhập, nhà và các trang đăng ký có thể truy cập ngay cả khi một trang không được đăng nhập vào hệ thống. Đăng xuất, liên hệ và về các trang sẽ chỉ hiển thị khi người dùng đã đăng nhập.

Trong tệp nav.php, contact.php, about.php và logout.php phải được đặt trong một câu lệnh IF sẽ kiểm tra xem phiên [có đăng nhập_in,] có tồn tại không. Nếu nó tồn tại, các trang này sẽ có thể truy cập được.contact.php, about.php, and logout.php should be enclosed in an if statement which will check if the session [“logged_in”] exists. If it exists, these pages will be accessible.

<?php 
include 'protect.php';
?>

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Contact us</title>
    <link rel="icon" type="image/x-icon" href="images/logo.jfif">
    <link rel="stylesheet" type="text/css" href="css/bootstrap.min.css">
</head>

<body>
    <?php include 'nav.php'?>
    <div class="container justify-content-center">
        <div class="row d-flex">
            <div class="col-sm-4">
                <form action="">
                    <h2>send us a massage</h2>
                    <div class="form-group">
                        <label>Name</label>
                        <input type="text" class="form-control mb-4" placeholder="text">
                    </div>
                    <div class="form-group">
                        <label>Subject</label>
                        <input type="text" class="form-control mb-4" placeholder="subject">
                    </div>
                    <div class="form-group">
                        <label>Subject details</label>
                        <input type="text" class="form-control mb-4" placeholder="subject details">
                    </div>
                    <button>submit</button>
                </form>
            </div>
        </div>
    </div>
</body>
</html>
2

Hơn nữa, nếu phiên không được đặt, chúng tôi sẽ hướng người dùng đến trang đăng nhập. Sửa đổi Nav.php trong Đăng nhập.php bằng cách đặt nó trong một câu lệnh IF như sau:

<?php 
include 'protect.php';
?>

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Contact us</title>
    <link rel="icon" type="image/x-icon" href="images/logo.jfif">
    <link rel="stylesheet" type="text/css" href="css/bootstrap.min.css">
</head>

<body>
    <?php include 'nav.php'?>
    <div class="container justify-content-center">
        <div class="row d-flex">
            <div class="col-sm-4">
                <form action="">
                    <h2>send us a massage</h2>
                    <div class="form-group">
                        <label>Name</label>
                        <input type="text" class="form-control mb-4" placeholder="text">
                    </div>
                    <div class="form-group">
                        <label>Subject</label>
                        <input type="text" class="form-control mb-4" placeholder="subject">
                    </div>
                    <div class="form-group">
                        <label>Subject details</label>
                        <input type="text" class="form-control mb-4" placeholder="subject details">
                    </div>
                    <button>submit</button>
                </form>
            </div>
        </div>
    </div>
</body>
</html>
3

Sự kết luận

Trong hướng dẫn này, chúng tôi đã học cách kiểm soát quyền truy cập vào các trang cụ thể bằng PHP. Các đối tượng phiên $ cho phép chúng tôi giám sát các tương tác của người dùng trên các trang web. Do đó, chúng ta có thể xác định xem chúng có đăng nhập hay không và do đó, gọi các hành động thích hợp.

Do đó, bạn có thể sử dụng kiến ​​thức này để tạo ra các ứng dụng đẹp và chất lượng cao khác.


Đóng góp đánh giá ngang hàng của: Wanja Mike

Các cấp độ truy cập người dùng khác nhau là gì?

Mức truy cập của người dùng phụ thuộc vào quyền (còn được gọi là quyền, nhóm người dùng, bit hoặc cờ) được gán cho các tài khoản. Có hai loại cân bằng truy cập: tự động và được yêu cầu.automatic, and requested.

Làm thế nào PHP có thể được sử dụng để kiểm soát quyền truy cập của người dùng?

ACL (Danh sách kiểm soát truy cập) là danh sách kiểm soát các quyền đối tượng, xác định người dùng nào có thể thực thi một tác vụ nhất định.Nó có thể được mở rộng thêm để chứa không chỉ người dùng, mà cả các nhóm người dùng.Đây là một khía cạnh quan trọng của bảo mật PHP và được sử dụng trong hầu hết các ứng dụng có kích thước trung bình và lớn.. It can be further extended to contain not only users, but also user groups. This is an important aspect of PHP security and is used in virtually all medium- and large-sized applications.

Mức truy cập người dùng hoạt động như thế nào?

Cấp truy cập cấp hoặc hạn chế quyền truy cập vào các tính năng Cổng thông tin web.Điều này ngoài các quyền được cấp thông qua các nhóm bảo mật, cung cấp hoặc hạn chế các nhiệm vụ cụ thể.Mức truy cập cho phép quản trị viên cung cấp quyền truy cập cơ sở người dùng của họ vào các tính năng họ cần và chỉ trả tiền cho các tính năng đó.grant or restrict access to select web portal features. This is in addition to permissions granted through security groups, which provide or restrict specific tasks. Access levels enable administrators to provide their user base access to the features they need and only pay for those features.

Làm cách nào để hạn chế quyền truy cập vào một trang web trong PHP?

Hạn chế quyền truy cập vào PHP ...
Đăng nhập vào cPanel của bạn ..
Chuyển đến Trình quản lý tệp.Chọn root web public_html của bạn và nhấp vào GO ..
Tìm của bạn.Tệp HTACCESS và chỉnh sửa nó với Trình chỉnh sửa mã.Đặt mã sau vào của bạn.Htaccess.Sao chép ..