In today’s corporate environment, attendance systems play a critical role in workforce management. For tech giants like Baidu, Alibaba, and Tencent, building a robust and scalable clock-in system helps streamline operations, improve work discipline, and enable efficient HR management with accurate time-tracking data.
Before developing a PHP-based attendance system, it’s essential to understand the core functionality it should offer:
Let’s walk through how to build a basic but functional attendance system using PHP.
We need two main tables: one for storing user credentials and the other for attendance logs.
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)
);
Login functionality is critical to track attendance per user. Here's a basic login example in PHP:
session_start();
if ($_SERVER["REQUEST_METHOD"] == "POST") {
$username = $_POST['username'];
$password = $_POST['password'];
// Database authentication logic
$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 login, the user can clock in, and the current time will be recorded in the system:
$now = date("H:i:s");
$user_id = $_SESSION['user_id'];
// Record the clock-in time
$query = "INSERT INTO attendance (user_id, clock_in) VALUES ('$user_id', '$now')";
mysqli_query($conn, $query);
echo "Clock-in successful at: $now";
Functionality alone is not enough—an effective attendance system should also offer a great user experience:
This guide demonstrated how to build a practical clock-in system using PHP, with a focus on modular design and essential features like login and time tracking. Whether you're building for a startup or a large corporation like BAT, these steps provide a strong foundation for developing a customized attendance solution.