📲 Download Utility Tools Apps

EMI Calculator

Download EMI Calculator

SOA Games

Download SOA Games

SOA Technology App

Download SOA Technology

BMI Checker

Download BMI Checker

Task Jira

Download Task Jira

Laughing Adda

Download Laughing Adda

📅 हिंदी कैलेंडर ऐप डाउनलोड करें

Download Shubhcalendar App

Mini Project: Smart Login + Dashboard System

🎯 Features:

  • Login system
  • Form validation
  • Role-based dashboard
  • Status using ternary
  • Match (modern PHP)

📁 1. index.php (Login Form)

<form method="POST" action="login.php">
<h2>Login</h2>

<input type="text" name="username" placeholder="Enter Username"><br><br>
<input type="password" name="password" placeholder="Enter Password"><br><br>

<button type="submit">Login</button>
</form>

🔐 2. login.php (Validation + Login Logic)

<?php
$username = $_POST['username'] ?? '';
$password = $_POST['password'] ?? '';// ✅ Form Validation (if-else)
if (empty($username) || empty($password)) {
echo "All fields are required ❗";
exit;
}// ✅ Dummy Users (Database simulation)
$users = [
"admin" => ["password" => "1234", "role" => "admin"],
"john" => ["password" => "1111", "role" => "user"],
"editor"=> ["password" => "2222", "role" => "editor"]
];// ✅ Login Check
if (isset($users[$username]) && $users[$username]['password'] === $password) {

$role = $users[$username]['role']; // ✅ Ternary (status message)
$status = ($role === "admin") ? "High Privilege User" : "Normal User"; echo "Login Successful ✅<br>";
echo "Status: $status <br>"; // Redirect to dashboard
header("refresh:2;url=dashboard.php?role=$role");} else {
echo "Invalid Credentials ❌";
}
?>

🧠 3. dashboard.php (Switch + Match)

<?php
$role = $_GET['role'] ?? 'guest';echo "<h2>Dashboard</h2>";// ✅ Switch Case (old method)
switch ($role) {
case "admin":
echo "Welcome Admin 👑<br>";
break;
case "editor":
echo "Welcome Editor ✍️<br>";
break;
case "user":
echo "Welcome User 👤<br>";
break;
default:
echo "Welcome Guest 🚫<br>";
}// ✅ Match Expression (modern PHP 8+)
$access = match($role) {
"admin" => "You have FULL access",
"editor" => "You can EDIT content",
"user" => "You can VIEW content",
default => "No Access",
};echo "<br>Access Level: $access";
?>

🧪 What Students Learn

✔ If-Else → form validation & login
✔ Ternary → quick status logic
✔ Switch → role-based UI
✔ Match → modern cleaner logic
✔ Real-world structure (multi-file project)


💡 Extra Improvements (Homework)

Ask students to:

  • Add logout button
  • Use sessions instead of GET
  • Add registration page
  • Store users in database (MySQL)

🎯 Teaching Tip

Run this project locally (XAMPP/WAMP):

http://localhost/project-folder/


AI Spiritual Tools & Interactive Experiences

Explore powerful AI-driven tools for daily guidance, spirituality, fun quizzes, and self-discovery.

Today’s Quote

Get inspiring daily quotes powered by AI to motivate and guide your day.

Explore Now

AI Tarot Card Reader

Reveal insights about your future, love, and career with AI tarot readings.

Read Tarot

Love Match Calculator

Check compatibility and love predictions using AI-based analysis.

Check Match

Fortune Cookie

Open an AI fortune cookie and receive wisdom, luck, and fun messages.

Open Cookie

Quiz Categories

Engage with knowledge-based and fun quizzes across multiple categories.

Start Quiz

Panchang Calendar

View daily Panchang, auspicious timings, tithi, nakshatra, and festivals.

View Panchang

Online Numerology

Discover your destiny number, life path, and numerology predictions.

Calculate Now

Spiritual Feeds

Stay connected with spiritual thoughts, mantras, and divine content.

View Feeds

Quiz Hub

Attempt trending quizzes on GK, spirituality, festivals, and more.

Explore Quizzes