A simple PHP fullstack application for testing CDN integration with user-uploaded content.
This project is designed to test CDN integration by creating a simple website that allows users to upload, store, and retrieve media content. The application includes user authentication, post management, and video streaming capabilities.
-
User Authentication
- Registration with email verification
- Login/logout functionality
- Password reset
-
Content Management
- Post creation with text and image uploads
- Video uploads and streaming
- Content listing and filtering
-
URL Signing
- JWT-based URL signing for secure content access
- Temporary access tokens for media resources
- Frontend: PHP, HTML, CSS, JavaScript
- Backend: PHP
- Database: MySQL
- Authentication: Custom PHP authentication system
- URL Signing: JWT (JSON Web Tokens)
- Form Handling: PHP form validation
- File Storage: Local (dev)
├── public/ # Public web root
│ ├── index.php # Entry point
│ ├── assets/ # Static assets (CSS, JS, images)
│ └── uploads/ # User uploaded files (dev only)
├── src/
│ ├── controllers/ # Controller classes
│ │ ├── AuthController.php # Authentication controllers
│ │ ├── PostController.php # Post management
│ │ ├── VideoController.php # Video management
| | └── mediaController.php # for controll access of vides and images and check tokens
│ ├── models/ # Database models
│ │ ├── User.php # User model
│ │ ├── Post.php # Post model
│ │ └── Video.php # Video model
│ ├── views/ # PHP templates
│ │ ├── auth/ # Login/registration pages
│ │ ├── posts/ # Post listing and details
│ │ ├── videos/ # Video listing and player
│ │ └── layouts/ # Layout templates
│ ├── lib/ # Utility functions and services
│ │ ├── Database.php # Database connection
│ │ ├── Auth.php # Authentication helpers
│ │ ├── Router.php # Routing system
│ │ └── CDN.php # CDN integration
│ └── config/ # Configuration files
├── composer.json # PHP dependencies
├── .htaccess # Apache config
└── db/ # Database migrations and seeds
-- Users Table
CREATE TABLE users (
id VARCHAR(36) PRIMARY KEY,
email VARCHAR(255) UNIQUE NOT NULL,
name VARCHAR(255),
password VARCHAR(255) NOT NULL,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
);
-- Posts Table
CREATE TABLE posts (
id VARCHAR(36) PRIMARY KEY,
title VARCHAR(255) NOT NULL,
content TEXT,
image_url VARCHAR(255),
cdn_url VARCHAR(255),
user_id VARCHAR(36) NOT NULL,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE
);
-- Videos Table
CREATE TABLE videos (
id VARCHAR(36) PRIMARY KEY,
title VARCHAR(255) NOT NULL,
description TEXT,
video_url VARCHAR(255) NOT NULL,
cdn_url VARCHAR(255),
thumbnail_url VARCHAR(255),
duration INT,
user_id VARCHAR(36) NOT NULL,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE
);- PHP 8.0+
- MySQL database
- Composer
- Apache/Nginx web server
-
Clone the repository.
-
Install or update dependencies:
# First time setup composer install # To update dependencies composer update
-
Create a
.envfile with the following variables:# Database DB_HOST=localhost DB_NAME=cdn_test DB_USER=root DB_PASS=password # Auth AUTH_SECRET=your-secret-key # URL Signing JWT_SECRET=your-jwt-secret-key -
Initialize the database:
php db/migrate.php
-
install dependencies:
composer udpate-
Configure your web server to point to the
publicdirectory. -
Access the application at
http://localhostor your configured domain.
The project implements URL signing using JSON Web Tokens (JWT) to provide temporary, secure access to media resources:
- Generates time-limited tokens for accessing media files
- Prevents unauthorized direct access to uploaded content
- Supports granular access control based on user permissions
- When a user requests a media resource, a temporary signed URL is generated
- The signed URL contains:
- Resource identifier
- Expiration timestamp
- User permissions
- Backend validates the token before serving the content
- Expired or tampered tokens are automatically rejected
The project includes Docker configuration for easy deployment:
-
Make sure Docker and Docker Compose are installed on your server.
-
Configure environment variables in the
.envfile. -
Build and start the containers:
docker-compose up -d
-
Access the application at
http://localhost:80or your configured domain.
POST /auth/register.php- Register a new userPOST /auth/login.php- Log in a userGET /auth/logout.php- Log out a userPOST /auth/reset-password.php- Reset user password
GET /posts/index.php- Get all postsGET /posts/view.php?id=:id- Get a specific postPOST /posts/create.php- Create a new postPOST /posts/edit.php?id=:id- Update a postPOST /posts/delete.php?id=:id- Delete a post
GET /videos/index.php- Get all videosGET /videos/view.php?id=:id- Get a specific videoPOST /videos/upload.php- Upload a new videoPOST /videos/edit.php?id=:id- Update video informationPOST /videos/delete.php?id=:id- Delete a video