Skip to content

Modern blog CMS with PHP 7.4+ & MySQL featuring OWASP security standards, demo mode protection, and session-based content isolation. Full CRUD admin panel with responsive UI. Portfolio project showcasing secure coding practices.

License

Notifications You must be signed in to change notification settings

mrajguruu/PostForge

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

14 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸ“ PostForge

PostForge Cover

PHP MySQL Bootstrap JavaScript

Portfolio Project Status Security Lines of Code

Forge Your Content Empire - A modern, secure blog management system built with PHP and MySQL

πŸŽ“ Portfolio Project - This project demonstrates full-stack PHP development, enterprise-grade security practices, and modern web application architecture. Built to showcase professional-level coding standards and security awareness.

🌐 Live Demo β€’ Quick Start β€’ Features β€’ Screenshots β€’ Tech Stack β€’ Security


🌐 Live Demo

Try PostForge live: https://postforge.infinityfree.me

Demo Credentials:

  • Email: admin@blog.com
  • Password: admin123

πŸ›‘οΈ Demo Mode Protection

PostForge features a smart demo mode that protects showcase content while allowing full CRUD testing:

  • βœ… Protected Demo Data: Existing posts and categories cannot be deleted
  • βœ… Full CRUD Testing: Create your own posts/categories to test all features
  • βœ… Session-Based Isolation: Your content is isolated from other visitors
  • βœ… Auto-Cleanup: Temporary content automatically removed after 24 hours

Try it: Attempt to delete a demo post, then create your own and delete it! Your changes won't affect other visitors.

What you can explore:

  • βœ… Admin dashboard with real-time analytics
  • βœ… Create, edit, and manage blog posts (with demo mode protection)
  • βœ… Category and comment management
  • βœ… Profile settings with image upload
  • βœ… Security features (rate limiting - try 5 wrong passwords!)
  • βœ… Responsive design on mobile and desktop

πŸ“‹ Table of Contents


⚑ Quick Start (60 seconds)

Get PostForge running on your local machine in under a minute - no configuration needed!

# 1. Clone the repository
git clone https://github.com/mrajguruu/PostForge.git
cd PostForge

# 2. Create database
mysql -u root -p -e "CREATE DATABASE blog_management CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci"

# 3. Import database schema
mysql -u root -p blog_management < sql/database.sql

# 4. Place in web server directory (XAMPP example)
# Copy to C:\xampp\htdocs\PostForge

# 5. Open in browser
# http://localhost/PostForge/public/index.php

πŸŽ‰ That's it! No .env file needed, no complex configuration. Login with:

  • Email: admin@blog.com
  • Password: admin123

Note: Works out-of-the-box with default XAMPP/WAMP settings (localhost, root user, no password)


πŸ“Έ Screenshots

Admin Dashboard

Admin Dashboard Real-time analytics with post stats, categories, comments, and recent activity

Post Management

Post Management Complete CRUD operations with rich text editor, image uploads, and category assignment

Login Page with Security

Login Page Secure login with rate limiting (5 attempts lockout) and session management

Public Homepage

Homepage Responsive 3-column grid layout with featured posts and category filtering

Profile Settings

Profile Settings WhatsApp-style profile picture upload with password management

Note: Screenshots showcase the actual working application. Clone and run to see it live!


🌟 Overview

PostForge is a comprehensive blog management system designed to provide a complete blogging platform with an intuitive admin panel. Built with security-first principles, this system offers robust content management capabilities, comment moderation, and a beautiful, responsive user interface.

Why PostForge?

  • Production-Ready: Industry best practices with clean, maintainable code
  • Complete CRUD: Full create, read, update, delete operations for posts and categories
  • Security-Focused: Implements OWASP security standards (CSRF, XSS, SQL injection prevention)
  • Modern UI/UX: Clean, professional design using Bootstrap 5
  • Profile Management: WhatsApp-style profile picture upload with intelligent time displays

🎯 Key Highlights

πŸ” Enterprise Security

  • Rate Limiting: 5 login attempts per 15 minutes
  • Brute Force Protection: 0.5s delay + account lockout
  • CSRF Tokens: Timing-safe comparison
  • SQL Injection: PDO prepared statements
  • XSS Protection: Output sanitization
  • Session Security: HTTPOnly + SameSite cookies

⚑ Modern Features

  • Environment-Based Config: Dev/Production modes
  • Smart Time Display: "Just now" to "5 years ago"
  • Profile Uploads: WhatsApp-style interface
  • Responsive Design: Bootstrap 5 grid system
  • Admin Dashboard: Real-time analytics
  • Comment Moderation: Spam filtering

πŸ“Š Technical Metrics

  • Lines of Code: 3,500+
  • Security Features: 10+
  • PHP Files: 21
  • Database Tables: 4 (normalized design)
  • Security Score: A+ Grade

✨ Features

πŸ” Authentication & Authorization

  • Secure login system with password hashing (bcrypt)
  • Session management with timeout protection
  • CSRF protection on all forms
  • Remember me functionality
  • Secure logout

πŸ“ Post Management

  • Full CRUD Operations
    • Create, read, update, and delete blog posts
    • Rich text editor for content creation
    • Featured image upload with validation
    • Auto-slug generation from titles
    • Excerpt generation
  • Post Organization
    • Category assignment
    • Draft/Published status management
    • View counter
    • Search and filter capabilities
  • Advanced Features
    • Pagination (10 posts per page)
    • Bulk actions support
    • Image preview before upload
    • Responsive table layout
    • Demo mode protection (session-based content isolation)

πŸ“ Category Management

  • Create and manage post categories
  • Category-wise post count
  • Edit and delete categories
  • Protection against deleting categories with posts
  • SEO-friendly URL slugs

πŸ’¬ Comment System

  • Comment Moderation
    • Approve/reject comments
    • Mark as spam
    • Filter by status (pending, approved, spam)
    • Delete permanently
  • Public Comment Form
    • Name and email validation
    • Content sanitization
    • Auto-pending status
  • Admin Dashboard
    • Recent comments overview
    • Quick moderation actions
    • Link to parent post

πŸ“Š Dashboard Analytics

  • Real-time Statistics
    • Total posts count
    • Published vs draft posts
    • Total categories
    • Pending comments count
    • Total views across all posts
    • Total admin users count
  • Recent Activity
    • Latest 5 posts
    • Recent comments with moderation options
    • Quick action buttons
  • Visual Design
    • Color-coded stat cards
    • Responsive grid layout
    • Icon-based navigation

βš™οΈ Admin Settings

  • Profile Management
    • Profile picture upload with preview
    • WhatsApp-style camera overlay interface
    • Circular image cropping
    • Gradient placeholder with initials
  • Account Settings
    • Change password functionality
    • View account information
    • Last login tracking
  • Profile Display
    • Profile pictures on public posts
    • Author avatars in admin header
    • About Author sidebar widget

🌐 Public Frontend

  • Homepage
    • Featured post showcase
    • 3-column responsive grid
    • Post cards with thumbnails
    • Category badges
    • View and comment counts
  • Single Post View
    • Full-width featured image
    • Formatted content display
    • Author and date information
    • Comment section
    • Related posts
  • Category Pages
    • Filter posts by category
    • Breadcrumb navigation

πŸ• Time & Date Features

  • Intelligent Time Display
    • "Just now" for recent activity (0-10 seconds)
    • Seconds ago (10-59 seconds)
    • Minutes ago (1-59 minutes)
    • Hours ago (1-23 hours)
    • Days ago (1-6 days)
    • Weeks ago (1-4 weeks)
    • Months ago (1-11 months)
    • Years ago (1-4 years)
    • Full date for 5+ years old content
  • Timezone Handling
    • Configurable timezone support
    • Automatic synchronization with MySQL
    • Works globally with any timezone
    • Accurate relative time calculations

🎨 Design System

  • Color Palette
    • Primary Blue: #2563eb
    • Success Green: #10b981
    • Warning Orange: #f59e0b
    • Danger Red: #ef4444
  • Typography
    • Font: Inter, Segoe UI, Roboto
    • Responsive font sizes
    • Optimized readability
  • Components
    • Bootstrap 5 framework
    • Bootstrap Icons
    • Custom CSS enhancements
    • Smooth transitions and hover effects

πŸ’‘ Technical Challenges Solved

Challenge 1: Brute Force Attack Prevention

Problem: Login systems are vulnerable to automated password-guessing attacks that can try thousands of combinations.

Solution Implemented:

  • Session-based rate limiting tracking failed attempts
  • 5-attempt threshold with 15-minute account lockout
  • Countdown timer showing remaining lockout time
  • 0.5-second delay on each failed attempt to slow attackers
  • Remaining attempts counter to warn legitimate users

Code Reference: admin/login.php:22-38, admin/login.php:86-98

Impact: Prevents automated attacks while maintaining usability for legitimate users


Challenge 2: Timezone Synchronization Issues

Problem: Users across different timezones seeing incorrect "time ago" displays (e.g., "5 hours ago" for posts just created).

Solution Implemented:

  • Centralized timezone configuration in config/config.php
  • PHP timezone synchronized with MySQL server timezone
  • Intelligent time calculation using Unix timestamps
  • Progressive time display (seconds β†’ minutes β†’ hours β†’ days β†’ weeks β†’ months β†’ years)
  • Fallback to full date for very old content (5+ years)

Code Reference: includes/functions.php:109-179, config/config.php:42

Impact: Accurate time displays globally, better user experience


Challenge 3: Secure File Upload System

Problem: User-uploaded files can contain malicious code or exploit server vulnerabilities.

Solution Implemented:

  • MIME type verification using finfo (not just extension checking)
  • File size limits (2MB) to prevent resource exhaustion
  • Random filename generation (32-byte hex) to prevent overwriting
  • Extension whitelist (jpg, jpeg, png, gif only)
  • Separate upload directories for posts and profiles
  • Server-side validation before client-side

Code Reference: includes/functions.php:211-268

Impact: Prevents malicious uploads while allowing legitimate user content


Challenge 4: CSRF Attack Prevention

Problem: Attackers can trick authenticated users into performing unwanted actions.

Solution Implemented:

  • Cryptographically secure token generation using random_bytes(32)
  • Timing-safe token comparison with hash_equals() to prevent timing attacks
  • Token regeneration on each form display
  • Token validation on all state-changing operations

Code Reference: includes/functions.php:20-37

Impact: Protects against cross-site request forgery attacks


Challenge 5: Environment-Based Configuration

Problem: Need different settings for development (show errors) vs production (hide errors), without code changes.

Solution Implemented:

  • Environment detection using getenv() with sensible defaults
  • .env file support for production deployment
  • Automatic error handling based on environment
  • Database credentials fallback for local development
  • Zero-configuration local setup

Code Reference: config/config.php:9-59

Impact: Works out-of-box locally, easily deployable to production


Challenge 6: SQL Injection Prevention

Problem: User input in database queries can allow attackers to execute arbitrary SQL commands.

Solution Implemented:

  • PDO prepared statements for all database operations
  • Parameter binding for user inputs
  • No string concatenation in SQL queries
  • Input validation and type checking

Code Reference: All database operations use PDO, example: admin/login.php:53-54

Impact: Complete protection against SQL injection attacks


πŸ› οΈ Tech Stack

Backend

  • PHP 7.4+
    • Object-Oriented Programming
    • PDO for database operations
    • Prepared statements (SQL injection prevention)
    • Session management
    • File upload handling

Database

  • MySQL 5.7+ / MariaDB 10.3+
    • Normalized database design
    • Foreign key constraints
    • Indexes for performance
    • UTF-8 character support

Frontend

  • HTML5 - Semantic markup
  • CSS3 - Custom styling with CSS variables
  • Bootstrap 5.3 - Responsive framework
  • JavaScript (ES6+) - Client-side validation and interactivity
  • Bootstrap Icons - Comprehensive icon library

Development Tools

  • XAMPP/WAMP - Local development environment
  • Git - Version control
  • VS Code - Code editor

πŸ“₯ Installation

Prerequisites

Before you begin, ensure you have the following installed:

  • PHP >= 7.4
  • MySQL >= 5.7 or MariaDB >= 10.3
  • Apache web server
  • Composer (optional, for dependency management)

Step 1: Clone the Repository

git clone https://github.com/mrajguruu/PostForge.git
cd PostForge

Step 2: Database Setup

  1. Create Database

    # Access MySQL
    mysql -u root -p
    
    # Create database
    CREATE DATABASE blog_management CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
  2. Import Database Schema

    # Import the SQL file
    mysql -u root -p blog_management < sql/database.sql

    Or use phpMyAdmin:

    • Open phpMyAdmin
    • Select blog_management database
    • Go to Import tab
    • Choose sql/database.sql file
    • Click Go

Step 3: Configuration

  1. Environment Configuration (Recommended)

    Copy the .env.example file to .env:

    cp .env.example .env

    Edit .env with your settings:

    # Environment
    APP_ENV=development
    
    # Site Configuration
    SITE_NAME=PostForge
    SITE_URL=http://localhost/PostForge
    ADMIN_EMAIL=admin@postforge.com
    
    # Database
    DB_HOST=localhost
    DB_NAME=blog_management
    DB_USER=root
    DB_PASS=your_password_here
    
    # Timezone
    TIMEZONE=Asia/Kolkata

    Important: Never commit .env to version control! It's already in .gitignore.

  2. Alternative: Direct Configuration

    If not using .env, edit config/config.php directly:

    define('DB_HOST', 'localhost');
    define('DB_NAME', 'blog_management');
    define('DB_USER', 'root');
    define('DB_PASS', 'your_password_here');
  3. Configure Timezone Settings

    Edit config/config.php and set the timezone to match your MySQL server:

    // Set this to your server's timezone
    date_default_timezone_set('Asia/Kolkata');  // Change as needed

    Common Timezones:

    • Asia/Kolkata - India (IST)
    • America/New_York - US Eastern
    • Europe/London - UK
    • UTC - Universal Time
    • Asia/Tokyo - Japan
    • Australia/Sydney - Australia

    Important: This must match your MySQL server timezone for accurate time calculations and "time ago" displays.

  4. Set Up File Permissions

    # Make uploads and logs directories writable
    chmod 755 uploads/
    chmod 755 uploads/posts/
    chmod 755 uploads/profiles/
    chmod 755 logs/

Step 4: Create Required Directories

# Create necessary directories (if not exists)
mkdir -p uploads/posts
mkdir -p uploads/profiles
mkdir -p logs

Step 5: Web Server Configuration

Using XAMPP

  1. Copy project folder to C:\xampp\htdocs\
  2. Start Apache and MySQL from XAMPP Control Panel
  3. Access: http://localhost/PostForge/

Using WAMP

  1. Copy project folder to C:\wamp64\www\
  2. Start WAMP services
  3. Access: http://localhost/PostForge/

Using PHP Built-in Server

php -S localhost:8000 -t public/

Access at: http://localhost:8000

Step 6: Access the Application

  • Public Site: http://localhost/PostForge/public/index.php
  • Admin Panel: http://localhost/PostForge/admin/login.php

πŸ”‘ Demo Credentials

Admin Login

Email: admin@blog.com
Password: admin123

Note: Change these credentials in production! The password hash in the database uses bcrypt.


πŸ“ Project Structure

PostForge/
β”‚
β”œβ”€β”€ πŸ“ config/
β”‚   β”œβ”€β”€ config.php              # Site configuration
β”‚   └── database.php            # Database connection (PDO)
β”‚
β”œβ”€β”€ πŸ“ admin/
β”‚   β”œβ”€β”€ login.php               # Admin login page
β”‚   β”œβ”€β”€ logout.php              # Logout script
β”‚   β”œβ”€β”€ dashboard.php           # Main admin dashboard
β”‚   β”œβ”€β”€ posts.php               # All posts listing
β”‚   β”œβ”€β”€ post-form.php           # Add/Edit post form
β”‚   β”œβ”€β”€ categories.php          # Category management
β”‚   β”œβ”€β”€ comments.php            # Comment moderation
β”‚   β”œβ”€β”€ settings.php            # Admin settings & profile
β”‚   └── πŸ“ includes/
β”‚       β”œβ”€β”€ header.php          # Admin header
β”‚       β”œβ”€β”€ sidebar.php         # Admin sidebar
β”‚       └── footer.php          # Admin footer
β”‚
β”œβ”€β”€ πŸ“ public/
β”‚   β”œβ”€β”€ index.php               # Homepage
β”‚   β”œβ”€β”€ post.php                # Single post view
β”‚   β”œβ”€β”€ category.php            # Category posts
β”‚   └── πŸ“ includes/
β”‚       β”œβ”€β”€ header.php          # Public header
β”‚       └── footer.php          # Public footer
β”‚
β”œβ”€β”€ πŸ“ assets/
β”‚   β”œβ”€β”€ πŸ“ css/
β”‚   β”‚   β”œβ”€β”€ admin.css           # Admin panel styles
β”‚   β”‚   └── public.css          # Public site styles
β”‚   β”œβ”€β”€ πŸ“ js/
β”‚   β”‚   β”œβ”€β”€ admin.js            # Admin JavaScript
β”‚   β”‚   └── public.js           # Public JavaScript
β”‚   └── πŸ“ images/
β”‚       └── logo.png            # Site logo
β”‚
β”œβ”€β”€ πŸ“ uploads/
β”‚   β”œβ”€β”€ πŸ“ posts/               # Uploaded post images
β”‚   └── πŸ“ profiles/            # Admin profile pictures
β”‚
β”œβ”€β”€ πŸ“ includes/
β”‚   β”œβ”€β”€ functions.php           # Helper functions
β”‚   └── auth.php                # Authentication middleware
β”‚
β”œβ”€β”€ πŸ“ sql/
β”‚   └── database.sql            # Database schema & demo data
β”‚
β”œβ”€β”€ .gitignore                  # Git ignore rules
└── README.md                   # This file

πŸ”’ Security Features

1. Password Security

// Password hashing with bcrypt
$hashed = password_hash($password, PASSWORD_BCRYPT);

// Verification
password_verify($input, $hashed);

2. SQL Injection Prevention

// Using prepared statements
$stmt = $pdo->prepare("SELECT * FROM posts WHERE id = :id");
$stmt->execute(['id' => $id]);

3. XSS Protection

// Output escaping
echo htmlspecialchars($data, ENT_QUOTES, 'UTF-8');

4. CSRF Protection

// Token generation
$_SESSION['csrf_token'] = bin2hex(random_bytes(32));

// Validation
hash_equals($_SESSION['csrf_token'], $_POST['csrf_token']);

5. Session Security

session_start([
    'cookie_httponly' => true,
    'cookie_samesite' => 'Strict'
]);
session_regenerate_id(true);

6. File Upload Validation

  • File type checking (MIME type)
  • File size limits (2MB maximum)
  • Random filename generation
  • Extension whitelist

7. Demo Mode Protection

// Protect demo data from deletion
if ($post['is_demo'] == 1) {
    redirect('posts.php', 'Cannot delete demo content...', 'warning');
}

// Session-based content isolation
$_SESSION['user_created_posts'][] = $newPostId;

// Auto-cleanup temporary content
DELETE FROM posts WHERE is_demo = 0 AND created_at < DATE_SUB(NOW(), INTERVAL 24 HOUR);

Features:

  • Session-based temporary content tracking
  • Protected demo data (cannot be deleted by visitors)
  • Auto-cleanup of visitor-created content after 24 hours
  • Content isolation between different users

πŸš€ Production Deployment

Pre-Deployment Checklist

Before deploying to production, complete these critical steps:

  1. Environment Configuration

    # Copy .env.example to .env
    cp .env.example .env
    
    # Edit .env and set:
    APP_ENV=production
    SITE_URL=https://yourdomain.com
    DB_PASS=strong_password_here
  2. Security Hardening

    • βœ… Ensure APP_ENV=production in .env (disables error display)
    • βœ… Set strong database password
    • βœ… Change default admin password after first login
    • βœ… Update ADMIN_EMAIL to real email address
    • βœ… Enable HTTPS (use Let's Encrypt or similar)
    • βœ… Review and restrict file permissions
  3. File Permissions (Linux/Unix)

    # Set directory permissions
    find . -type d -exec chmod 755 {} \;
    
    # Set file permissions
    find . -type f -exec chmod 644 {} \;
    
    # Make uploads and logs writable
    chmod 755 uploads/ uploads/posts/ uploads/profiles/ logs/
  4. Database Security

    • Create a dedicated MySQL user (don't use root)
    • Grant only necessary privileges
    CREATE USER 'postforge_user'@'localhost' IDENTIFIED BY 'strong_password';
    GRANT SELECT, INSERT, UPDATE, DELETE ON blog_management.* TO 'postforge_user'@'localhost';
    FLUSH PRIVILEGES;
  5. Apache Configuration (Recommended) Create .htaccess in root directory:

    # Disable directory listing
    Options -Indexes
    
    # Protect sensitive files
    <FilesMatch "\.(env|log|sql|md)$">
        Order allow,deny
        Deny from all
    </FilesMatch>
    
    # Enable HTTPS redirect
    RewriteEngine On
    RewriteCond %{HTTPS} off
    RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
  6. Monitoring & Maintenance

    • Monitor logs/php-errors.log regularly
    • Set up automated database backups
    • Keep PHP and MySQL updated
    • Review security logs periodically

⚠️ Common Issues

Database Connection Error

Solution: Check config/config.php and verify MySQL credentials

Upload Directory Not Writable

Solution: chmod 755 uploads/ uploads/posts/

Blank Page After Login

Solution: Check PHP error logs, ensure session is started

Images Not Displaying

Solution: Verify UPLOAD_URL in config.php matches your server path

Time Shows Incorrectly (Wrong Hours)

Problem: Comments or posts showing "5 hours ago" when just posted
Solution: Set timezone in config/config.php to match MySQL server
Example: date_default_timezone_set('Asia/Kolkata');

Profile Pictures Not Uploading

Solution:
1. Create uploads/profiles/ directory
2. Set permissions: chmod 755 uploads/profiles/
3. Verify PROFILE_UPLOAD_DIR in config.php

🀝 Contributing

Contributions are welcome! This is a portfolio project, but I'm open to improvements and suggestions.

How to Contribute

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/AmazingFeature)
  3. Commit your changes (git commit -m 'feat: Add some AmazingFeature')
  4. Push to the branch (git push origin feature/AmazingFeature)
  5. Open a Pull Request

Please read CONTRIBUTING.md for details on the code of conduct and development process.

Areas for Improvement

  • Unit tests with PHPUnit
  • API endpoints for mobile app
  • Multi-language support
  • Email notifications
  • Dark mode theme

πŸ“ License

This project is licensed under the MIT License - see the LICENSE file for details.

MIT License - Copyright (c) 2025 PostForge

πŸ“ž Contact & Links

Developer: Mohit Rajguru

Project Links:


Made with ❀️ using PHP & MySQL

If you found this project helpful, please give it a ⭐!

πŸŽ“ Built as a Portfolio Project

This project demonstrates:

  • βœ… Full-stack PHP development
  • βœ… Enterprise-grade security (OWASP standards)
  • βœ… Modern web architecture
  • βœ… Production-ready code quality
  • βœ… Professional documentation

⬆ Back to Top

About

Modern blog CMS with PHP 7.4+ & MySQL featuring OWASP security standards, demo mode protection, and session-based content isolation. Full CRUD admin panel with responsive UI. Portfolio project showcasing secure coding practices.

Topics

Resources

License

Contributing

Security policy

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 2

  •  
  •