A minimal and secure backend API for anonymous visit tracking with engineering practices focused on simplicity, security, maintainability, and clarity.
This project integrates:
- A secure PHP API for anonymous page visit tracking
- A MySQL database for storing aggregated visit metrics
- A CI/CD system with GitHub Actions
Security is a primary concern in this project. While the application is intentionally simple, the architecture follows several best practices to minimize risk and ensure reliable operation even in shared hosting environments.
- Protect server resources from unauthorized requests
- Prevent credential exposure
- Avoid collecting or storing personal data
- Ensure database integrity
- Maintain a small, auditable attack surface
- Enable safe public hosting of the entire codebase
- Visit-tracking endpoint protected by token-based authentication
- Token stored exclusively in GitHub Secrets
.envgenerated dynamically during deployment- Unauthorized requests rejected early
No personal data is collected:
- No IP
- No User-Agent
- No geolocation
- No cookies
Stored fields only:
- Timestamp
- Page path (URL)
- Referrer
- All inputs validated and sanitized
- Prepared statements only
- No dynamic SQL
- Restricted input sizes
- A single, stateless backend endpoint
- No file uploads
- No session management
- No SSR, templating, or dynamic routing
- No admin interfaces
- Stateless POST endpoint
- Token-based authorization
- Sanitized inputs
- PDO prepared statements
.envbased configuration- No cookies, no sessions, no PII
CREATE TABLE visit_logs (
id BIGINT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
page_path VARCHAR(255) NOT NULL,
referrer VARCHAR(512) NULL,
created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
INDEX idx_path (page_path),
INDEX idx_created_at (created_at)
) ENGINE = InnoDB DEFAULT CHARSET = utf8mb4 COLLATE = utf8mb4_unicode_ci;No personal data is stored.
Create config/.env file from config/.env.example and set the variables.
Use Docker for local MySQL:
docker run -d --name docs-db \
-e MYSQL_ROOT_PASSWORD=root \
-e MYSQL_DATABASE=dbname \
-p 3306:3306 mysql:8Run PHP backend:
php -S localhost:8000 -t backendOpen terminal and call the endpoint:
curl -X POST http://localhost:8000/api/visit.php \
-H "Content-Type: application/json"
-H "X-Visit-Token: token"
-d '{"page_path": "/", "referrer": ""}'- Generates
.env - Deploys backend folder
- Manual approval required
- Uses FTP-Deploy-Action
- Linux + Apache
- PHP 8.3
- MySQL/MariaDB
- FTPS enabled
This project is licensed under the MIT License — see the LICENSE file for details.
This project aims to balance:
- simplicity
- clean design
- secure engineering
- portability
- educational value