Overview
The QR Attendance System uses QR codes to enable quick and contactless attendance marking. Students generate unique QR codes containing their student ID, and teachers scan these codes to automatically record attendance with timestamp and status.QR Code Generation
Each student is assigned a unique QR code that encodes their student ID. The system uses the QRCode.js library to generate these codes dynamically on the student dashboard.Student QR Code Display
When students log in, their QR code is automatically generated using their student ID:student_dashboard.php:314-318
The QR code contains only the student ID as plain text. This ensures compatibility with any QR code scanner and keeps the implementation simple and reliable.
QR Code Properties
Size
128x128 pixels - optimized for mobile scanning
Content
Student ID in plain text format
Library
QRCode.js (CDN-hosted)
Regeneration
Generated fresh on each page load
Scanning Process
Teachers use the built-in QR scanner to capture student attendance. The scanner uses the Instascan library to access the device camera and decode QR codes in real-time.Scanner Implementation
The scanner page initializes a video preview and listens for QR code scans:scanner.php:42-62
Camera Selection
The system automatically selects the first available camera:scanner.php:65-76
Attendance Processing
When a QR code is scanned, the system validates the student, checks the schedule, and determines the attendance status based on the current time.Validation Flow
- Teacher Authorization - Verify the teacher is logged in
- Student Verification - Check if student exists and is enrolled in teacher’s class
- Schedule Check - Confirm there’s a class scheduled for today
- Duplicate Check - Ensure attendance hasn’t already been marked
- Status Calculation - Determine if on-time or late
- Record Creation - Insert attendance record into database
Student Validation
process_attendance.php:16-28
Schedule Verification
process_attendance.php:30-44
On-Time vs Late Detection
The system automatically determines whether a student is on-time or late by comparing the scan time against the class start time plus the grace period.Time Calculation
process_attendance.php:56-63
Status Logic
On-Time
Scanned within the start time + grace period
Late
Scanned after the grace period has expired
Recording Attendance
process_attendance.php:66-75
Response Messages
The system provides clear feedback messages for different scenarios:| Scenario | Message | Icon |
|---|---|---|
| On-time attendance | ”On-time attendance marked for Student ID: “ | ✅ |
| Late attendance | ”Late attendance marked for Student ID: “ | ⚠️ |
| Already marked | ”Attendance already marked for this class today” | ⚠️ |
| Student not found | ”Student not found in any of your classes” | ❌ |
| No schedule | ”No class scheduled for today with this teacher” | ❌ |
| Unauthorized | ”Unauthorized access” | ❌ |
All responses are displayed immediately in the scanner interface, providing instant feedback to both teacher and student.
Security Considerations
Teacher Authorization
Only logged-in teachers can process attendance:process_attendance.php:7-11
Class Ownership Validation
Teachers can only mark attendance for students in their own classes:process_attendance.php:22
Best Practices
QR Code Display
Students should have their QR code ready before class to speed up the scanning process
Camera Positioning
Hold the device steady and ensure good lighting for optimal scanning
Grace Period
Configure appropriate grace periods (typically 5-15 minutes) to account for minor delays
Duplicate Prevention
The system automatically prevents duplicate scans for the same class and date