QR Code Scanner
Page:scanner.php
Authentication: Teacher session required
Library: Instascan.js for camera-based QR code scanning
Scanner Implementation
Camera Selection
The scanner uses the device’s camera to read QR codes. Camera permissions must be granted by the user.
Process Attendance
Endpoint:process_attendance.php
Method: POST
Authentication: Teacher session required
Request Parameters
Student ID from scanned QR code
Processing Flow
-
Authentication Check:
-
Student Verification:
-
Schedule Verification:
-
Duplicate Check:
- Status Calculation & Recording
Attendance Status Calculation
Algorithm: Determines if student is on-time or late based on scheduleTime Comparison Logic
Status Values
Student checked in at or before start_time + grace_period
Student checked in after start_time + grace_period
Student did not check in (manually set by teacher or system)
Example Calculation
Schedule:- Start Time: 09:00 AM
- Grace Period: 15 minutes
- Late After: 09:15 AM
- 08:55 AM → on-time
- 09:00 AM → on-time
- 09:10 AM → on-time
- 09:15 AM → on-time
- 09:16 AM → late
- 09:30 AM → late
Grace period is inclusive. Students checking in exactly at the grace time cutoff are marked on-time.
Record Attendance
Database Operation:Attendance Record Fields
Student identifier from QR code
ID of the class from schedule
Current date (CURRENT_DATE())
Current time (CURRENT_TIME())
Calculated status: ‘on-time’ or ‘late’
Response Messages
Success Responses
On-time Attendance:Error Responses
Unauthorized:Validation Rules
1. Teacher Authorization
2. Student-Teacher Relationship
Student must be enrolled in one of the teacher’s classes:3. Schedule Validation
Class must be scheduled for the current day:- 1 = Sunday
- 2 = Monday
- 3 = Tuesday
- 4 = Wednesday
- 5 = Thursday
- 6 = Friday
- 7 = Saturday
4. Duplicate Prevention
Only one attendance record per student per class per day:Complete Processing Example
Scenario
Student: ID 12345Teacher: T1234
Class: Computer Science 101
Schedule: Monday 09:00 AM, Grace Period: 15 minutes
Check-in Time: 09:10 AM
Processing Steps
- QR Scan: Student shows QR code containing “12345”
- Teacher Auth: Verified T1234 is logged in
- Student Lookup: Found student 12345 in CS101 (teacher T1234’s class)
- Schedule Check: CS101 scheduled for Monday at 09:00 AM
- Duplicate Check: No attendance record for today
- Status Calc:
- Current: 09:10 AM
- Grace: 09:15 AM
- Status: on-time ✅
- Record: Insert attendance record
- Response: ”✅ On-time attendance marked for Student ID: 12345”
Database Record
Manual Status Updates
Teachers can manually update attendance status through the dashboard: Endpoint:teacher_dashboard.php (POST)
Set to “1”
ID of attendance record to update
New status: ‘on-time’, ‘late’, or ‘absent’
Update Query
Manual updates allow teachers to correct attendance status if a student was marked incorrectly.
Error Handling
All database operations are wrapped in try-catch blocks:Common Errors
Invalid Student ID:- Student doesn’t exist in database
- Student not enrolled in any teacher’s classes
- No schedule set for class
- Class not scheduled for current day
- Connection failures
- Constraint violations
- Transaction rollbacks