Skip to content

yashguram/cms

Repository files navigation

PHP Content Management System

A complete Content Management System built using PHP, MySQL, HTML, CSS, JavaScript, jQuery, and Bootstrap.

The project contains a public-facing news and blog website along with a separate admin dashboard. Administrators can manage posts, categories, comments, users, and profile information through CRUD operations.


Overview

This project was developed to understand how a complete dynamic website works with a PHP backend and a MySQL database.

The public website allows visitors to browse published posts, search content, view posts by category or author, register, log in, and submit comments.

The admin dashboard provides content-management functionality such as creating, reading, updating, and deleting posts, categories, users, and comments.


Features

Public Website

  • View published posts
  • Read complete post details
  • Browse posts by category
  • Browse posts by author
  • Search posts
  • Navigate posts using pagination
  • View post publication date
  • View post images and content
  • User registration
  • User login and logout
  • Submit comments on posts
  • Display approved comments
  • Track individual post views
  • Responsive Bootstrap navigation and layout

Admin Dashboard

  • Secure session-based admin area
  • Dashboard with total record counts
  • Display total posts
  • Display total comments
  • Display total users
  • Display total categories
  • Visual statistics using Google Charts
  • View published and draft post counts
  • View approved and unapproved comment counts
  • View admin and subscriber user counts
  • Online-user activity counter

Post Management

  • Add new posts
  • View all posts
  • Edit existing posts
  • Delete posts
  • Upload post images
  • Assign categories to posts
  • Add post title
  • Add post author
  • Add post tags
  • Add rich-text post content
  • Set post status as published or draft
  • Perform bulk operations on selected posts
  • Track post views and comment counts

Category Management

  • Add new categories
  • View all categories
  • Edit categories
  • Delete categories

Comment Management

  • View all submitted comments
  • Approve comments
  • Unapprove comments
  • Delete comments
  • Associate comments with individual posts
  • Display only approved comments on the public website

User Management

  • Add new users
  • View all users
  • Edit user information
  • Delete users
  • Assign admin or subscriber roles
  • Promote or demote users
  • Register new subscriber accounts
  • Update profile information

Technologies Used

Frontend

  • HTML5
  • CSS3
  • JavaScript
  • jQuery
  • Bootstrap
  • Font Awesome
  • Summernote Rich Text Editor
  • Google Charts

Backend

  • PHP
  • MySQL
  • MySQLi

Development Environment

  • Apache Server
  • XAMPP, WAMP, or LAMP
  • phpMyAdmin

PHP Concepts Practised

This project helped me practise:

  • PHP syntax and server-side rendering
  • PHP includes
  • Form handling
  • GET and POST requests
  • Sessions
  • Authentication
  • Role-based access
  • Password hashing
  • Password verification
  • File uploads
  • Redirects using headers
  • Reusable PHP functions
  • Conditional rendering
  • Dynamic page routing using query parameters
  • Pagination
  • Working with arrays
  • Error handling
  • Database connections
  • MySQL queries
  • CRUD operations
  • Aggregate database counts
  • Search functionality
  • Comment moderation

Database Operations

The project performs all four main CRUD operations.

Create

  • Create posts
  • Create categories
  • Create users
  • Create comments
  • Register new accounts

Read

  • Display posts
  • Display categories
  • Display users
  • Display comments
  • Display dashboard statistics
  • Search and filter content

Update

  • Edit posts
  • Update post status
  • Edit categories
  • Update users
  • Update profiles
  • Approve or unapprove comments

Delete

  • Delete posts
  • Delete categories
  • Delete users
  • Delete comments

Project Structure

cms-main/
│
├── admin/
│   ├── css/
│   ├── font-awesome/
│   ├── includes/
│   │   ├── add_post.php
│   │   ├── add_user.php
│   │   ├── admin_footer.php
│   │   ├── admin_header.php
│   │   ├── admin_navbar.php
│   │   ├── edit_post.php
│   │   ├── edit_user.php
│   │   ├── functions.php
│   │   ├── update_cat.php
│   │   ├── user_edit_profile.php
│   │   ├── view_all_comments.php
│   │   ├── view_all_post.php
│   │   └── view_all_users.php
│   │
│   ├── js/
│   ├── admin_comments.php
│   ├── admin_post.php
│   ├── admin_users.php
│   ├── categories.php
│   ├── index.php
│   └── profile.php
│
├── css/
│   ├── blog-home.css
│   ├── blog-post.css
│   ├── bootstrap.css
│   ├── bootstrap.min.css
│   └── style.css
│
├── fonts/
├── images/
│
├── includes/
│   ├── db.php
│   ├── footer.php
│   ├── header.php
│   ├── login.php
│   ├── logout.php
│   ├── navbar.php
│   ├── sidebar.php
│   └── sidewall.php
│
├── js/
│   ├── bootstrap.js
│   ├── bootstrap.min.js
│   └── jquery.js
│
├── author.php
├── category.php
├── comments.php
├── index.php
├── post.php
├── registration.php
├── search.php
└── README.md

Main Application Flow

Public Website Flow

  1. Published posts are fetched from the MySQL database.
  2. The posts are displayed on the home page.
  3. Visitors can open a complete post.
  4. Each post visit increments its view count.
  5. Visitors can filter posts by category or author.
  6. Visitors can search for posts.
  7. Users can register and log in.
  8. Visitors can submit comments.
  9. Submitted comments remain unapproved until reviewed by an administrator.
  10. Approved comments become visible on the public post page.

Admin Dashboard Flow

  1. The administrator logs into the system.
  2. PHP creates a session for the authenticated user.
  3. The administrator is redirected to the dashboard.
  4. Dashboard cards display totals for posts, comments, users, and categories.
  5. Google Charts display active and inactive content statistics.
  6. The administrator can manage all website content through CRUD operations.

Authentication and User Roles

The system supports two user roles:

Admin

Administrators can access the dashboard and manage:

  • Posts
  • Categories
  • Comments
  • Users
  • Profile information

Subscriber

Subscribers can register and log in to the public website.

PHP sessions are used to preserve authenticated user information.

Passwords are stored using PHP's password-hashing functionality:

password_hash($password, PASSWORD_DEFAULT);

During login, passwords are verified using:

password_verify($enteredPassword, $storedPassword);

Pagination

The home page divides posts into multiple pages.

The total number of pages is calculated using the total post count and the number of posts displayed per page.

$post_count = ceil($post_count / 3);

Each page displays a limited number of posts using a MySQL LIMIT query.


Comment Moderation

Comments submitted from the public website are initially stored with an unapproved status.

unapproved

An administrator can approve the comment from the dashboard.

Only comments with the following status are displayed publicly:

approved

This creates a basic moderation workflow for user-generated content.


Dashboard Analytics

The admin dashboard includes summary cards for:

  • Posts
  • Comments
  • Users
  • Categories

It also uses Google Charts to compare:

  • Total records
  • Active records
  • Inactive records

Examples include:

  • Published and draft posts
  • Approved and unapproved comments
  • Admin and subscriber users

Installation

Requirements

Before running the project, install one of the following local server environments:

  • XAMPP
  • WAMP
  • LAMP
  • MAMP

The environment should include:

  • Apache
  • PHP
  • MySQL
  • phpMyAdmin

1. Clone the Repository

git clone https://github.com/your-username/php-cms.git

2. Move the Project

For XAMPP, move the project folder into:

C:/xampp/htdocs/

Example:

C:/xampp/htdocs/cms-main/

3. Start the Services

Open the XAMPP Control Panel and start:

  • Apache
  • MySQL

4. Create the Database

Open phpMyAdmin:

http://localhost/phpmyadmin

Create a database named:

cms

5. Configure the Database Connection

The database connection is located in:

includes/db.php

Default configuration:

$db['hostname'] = "localhost";
$db['username'] = "root";
$db['password'] = "";
$db['dbname'] = "cms";

Change these values according to your local MySQL setup.

6. Create or Import the Required Tables

The application expects the following tables:

posts
categories
users
comments
user_online

Make sure the database schema contains the columns used by the application.

The current repository does not include a database SQL export. The database must be recreated or imported separately before running the complete application.

7. Run the Application

Open:

http://localhost/cms-main/

Admin dashboard:

http://localhost/cms-main/admin/

Expected Database Tables

Posts

Stores:

  • Post ID
  • Category ID
  • Title
  • Author
  • Date
  • Image
  • Content
  • Tags
  • Status
  • Comment count
  • View count

Categories

Stores:

  • Category ID
  • Category title

Users

Stores:

  • User ID
  • First name
  • Last name
  • Username
  • Password
  • Email
  • Role

Comments

Stores:

  • Comment ID
  • Related post ID
  • Author
  • Email
  • Content
  • Status
  • Date

Online Users

Stores:

  • Session ID
  • Activity time

Security Features

The project includes basic security practices such as:

  • Password hashing
  • Password verification
  • Session-based authentication
  • Role-based redirection
  • Input escaping using MySQLi
  • Restricted admin-page access

This project was developed as a learning project. Before using it in production, additional security improvements should be implemented.


Recommended Production Improvements

  • Use prepared statements for every database query
  • Add CSRF protection
  • Validate and sanitize all form inputs
  • Escape output before displaying it
  • Validate uploaded file type and size
  • Generate unique uploaded filenames
  • Restrict direct access to admin pages
  • Add stronger role checks for admin-only actions
  • Remove database credentials from source code
  • Store credentials using environment variables
  • Add duplicate username and email validation
  • Add password-strength validation
  • Add secure session-cookie settings
  • Add login rate limiting
  • Add confirmation before delete operations
  • Use POST requests instead of GET requests for destructive actions

Learning Outcome

While building this project, I learned:

  • How to build a complete PHP and MySQL web application
  • How frontend pages communicate with a backend
  • How to connect PHP with a MySQL database
  • How to perform CRUD operations
  • How to build a reusable PHP project structure
  • How to create a public website and separate admin panel
  • How to manage authenticated users using sessions
  • How to implement admin and subscriber roles
  • How to upload and display images
  • How to create a comment-approval workflow
  • How to implement pagination and search
  • How to display live database statistics
  • How to use Bootstrap for responsive layouts
  • How to organise a larger project using PHP includes

Future Improvements

  • Add a database SQL export file
  • Rewrite queries using prepared statements
  • Add CSRF tokens
  • Improve admin authorization
  • Add password-reset functionality
  • Add email verification
  • Add slug-based post URLs
  • Add a rich-text image-upload feature
  • Add post scheduling
  • Add reusable form-validation messages
  • Add activity logs
  • Add media-library management
  • Add responsive UI improvements
  • Add REST API endpoints
  • Rebuild the frontend using React
  • Use Laravel for a modern backend version

Author

Yash Guram

Computer Engineering graduate interested in frontend, backend, and full-stack web development.


Project Status

Completed full-stack learning project built with PHP, MySQL, JavaScript, jQuery, and Bootstrap.

About

A complete PHP and MySQL CMS with an admin dashboard, authentication, post CRUD, categories, users, comments, search, and pagination.

Topics

Resources

Stars

Watchers

Forks

Releases

Packages

Contributors

Languages