Google Login with Google

How to Build an Admin Dashboard in PHP (Step-by-Step)

How to Build an Admin Dashboard in PHP (Step-by-Step)


📌 What is an Admin Dashboard?

An admin dashboard is a control panel where admins can:

manage users
manage content
monitor activity

👉 It is essential for any real web application.

1️⃣ Create admin.php
/hosting/foliocraft/html/admin.php
2️⃣ Restrict access (Admin only)
<?php

require_once 'auth_role.php';

requireRole('admin');

?>

👉 Only admins can access this page

3️⃣ Basic dashboard layout
<?php include 'header.php'; ?>

<h1>Admin Dashboard</h1>

<ul>
<li><a href="manage_users.php">Manage Users</a></li>
<li><a href="manage_gallery.php">Manage Gallery</a></li>
</ul>
4️⃣ Show statistics
<?php

require_once 'db.php';

// Count users
$result = $conn->query("SELECT COUNT(*) as total FROM users");
$users = $result->fetch_assoc()['total'];

// Count images
$result = $conn->query("SELECT COUNT(*) as total FROM gallery");
$images = $result->fetch_assoc()['total'];

?>

<p>Total Users: <?= $users ?></p>
<p>Total Images: <?= $images ?></p>
5️⃣ Manage users page

Create:

/hosting/foliocraft/html/manage_users.php
Load users
<?php

require_once 'auth_role.php';
requireRole('admin');

require_once 'db.php';

$result = $conn->query("SELECT id, username, role FROM users");

while ($row = $result->fetch_assoc()):
?>

<div>
<?= $row['username'] ?> (<?= $row['role'] ?>)
</div>

<?php endwhile; ?>
6️⃣ Manage gallery (admin control)
/hosting/foliocraft/html/manage_gallery.php
<?php

require_once 'auth_role.php';
requireRole('admin');

require_once 'db.php';

$result = $conn->query("SELECT * FROM gallery ORDER BY id DESC");

while ($row = $result->fetch_assoc()):
?>

<div>
<img src="<?= $row['image_url'] ?>" width="100">
<a href="delete.php?id=<?= $row['id'] ?>">Delete</a>
</div>

<?php endwhile; ?>

👉 Admin can delete any image

🔥 Key Features
admin-only access
user management
content management
statistics overview
🔐 Security Tips
Always use role check
Never expose admin page publicly
Validate actions on server
Use prepared statements
✅ Summary

To build an admin dashboard:

Create admin page
Restrict access
Add navigation
Show statistics
Manage users/content
🚀 Next Step

You can extend this by:

admin UI design (cards, charts)
activity logs (who did what)
user role editor
search & filters

Hope this helps 🚀
← Back to list
💬 Comments (0)