task2
task2
access to specific pages, I'll guide you through the process using HTML and PHP for
the backend. We'll focus on the following:
home.html
html
Copy code
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Home</title>
</head>
<body>
<h1>Welcome to the Home Page</h1>
<p>Content for Group A.</p>
</body>
</html>
about-us.html
html
Copy code
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>About Us</title>
</head>
<body>
<h1>About Our Company</h1>
<p>Information for Group A.</p>
</body>
</html>
contact-us.html
html
Copy code
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Contact Us</title>
</head>
<body>
<h1>Contact Information</h1>
<p>Content for Group B.</p>
</body>
</html>
feedback.html
html
Copy code
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Feedback</title>
</head>
<body>
<h1>Feedback Form</h1>
<p>Feedback form for Group B.</p>
</body>
</html>
404.html (Access Denied Page)
html
Copy code
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>404 - Page Not Found</title>
</head>
<body>
<h1>404 - Page Not Found</h1>
<p>You do not have permission to view this page.</p>
<a href="/home.html">Go to Home Page</a>
</body>
</html>
2. Create PHP Logic to Handle Access Control
Now, we’ll create the server-side logic to determine which pages are accessible
based on the user’s group.
php
Copy code
<?php
session_start();
php
Copy code
<?php
session_start();
php
Copy code
<?php
include('check_access.php');
if (!check_access('home.html')) {
// Option 1: Redirect to 404 page
header('Location: /404.html');
exit();
if (!check_access('about-us.html')) {
header('Location: /404.html');
exit();
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>About Us</title>
</head>
<body>
<h1>About Our Company</h1>
<p>Information for Group A.</p>
</body>
</html>
contact-us.php (Access Control Applied to Contact Us Page)
php
Copy code
<?php
include('check_access.php');
if (!check_access('contact-us.html')) {
header('Location: /404.html');
exit();
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Contact Us</title>
</head>
<body>
<h1>Contact Information</h1>
<p>Content for Group B.</p>
</body>
</html>
feedback.php (Access Control Applied to Feedback Page)
php
Copy code
<?php
include('check_access.php');
if (!check_access('feedback.html')) {
header('Location: /404.html');
exit();
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Feedback</title>
</head>
<body>
<h1>Feedback Form</h1>
<p>Feedback form for Group B.</p>
</body>
</html>
4. Handle Access Denial
404.html (Access Denied Page)
This page is already set up in Step 1. It will show a message when a user is denied
access.
html
Copy code
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>404 - Page Not Found</title>
</head>
<body>
<h1>404 - Page Not Found</h1>
<p>You do not have permission to view this page.</p>
<a href="/home.html">Go to Home Page</a>
</body>
</html>
5. Testing the System
Login:
Log in as a user from Group A (username: group_a_user) or Group B (username:
group_b_user).
Access pages that are allowed for the group and ensure the user can view the pages.
Try accessing restricted pages and confirm the user is either redirected to the 404
page or shown a popup (based on your configuration).
Access Denied:
Try to manually access a URL (e.g., /contact-us.html for Group A) and verify that
the system properly handles the unauthorized access.
Final Notes:
This implementation uses PHP sessions for managing user login and access control.
Ensure your session is started (session_start()) at the beginning of every PHP file
that needs user authentication.
For production, you should also ensure that your login system is secure, e.g., by
hashing passwords and using HTTPS.