In modern business management, attendance systems play a critical role in human resource operations. For major enterprises like Baidu, Alibaba, and Tencent, a reliable and efficient time-tracking system ensures accurate work-hour records and supports performance evaluation. This article outlines how to build a functional check-in system using PHP.
Before development begins, it's essential to define the core features of the system:
The system requires two main tables: one for users and another for attendance records. Here's a sample structure:
CREATE TABLE users (
id INT AUTO_INCREMENT PRIMARY KEY,
username VARCHAR(50) NOT NULL,
password VARCHAR(255) NOT NULL
);
CREATE TABLE attendance (
id INT AUTO_INCREMENT PRIMARY KEY,
user_id INT NOT NULL,
clock_in TIME NOT NULL,
clock_out TIME,
FOREIGN KEY (user_id) REFERENCES users(id)
);
User authentication is a prerequisite for accessing the system. Below is a simplified PHP snippet for login functionality:
session_start();
if ($_SERVER["REQUEST_METHOD"] == "POST") {
$username = $_POST['username'];
$password = $_POST['password'];
// Validate against database
$query = "SELECT * FROM users WHERE username='$username'";
$result = mysqli_query($conn, $query);
$user = mysqli_fetch_assoc($result);
if (password_verify($password, $user['password'])) {
$_SESSION['user_id'] = $user['id'];
header("Location: clock_in.php");
} else {
echo "Invalid username or password";
}
}
After logging in, users can record their attendance using the following PHP code:
$now = date("H:i:s");
$user_id = $_SESSION['user_id'];
// Insert attendance record
$query = "INSERT INTO attendance (user_id, clock_in) VALUES ('$user_id', '$now')";
mysqli_query($conn, $query);
echo "Clock-in successful at: $now";
Beyond core features, improving user experience is vital. Consider the following enhancements:
This guide demonstrates how to create a functional attendance tracking system using PHP. From setting up the database to implementing user login and time record functions, it provides a solid foundation for enterprise-level HR systems. By following these practices, developers can build efficient and scalable attendance features to meet organizational needs.