Modernize phpblog: Migrate to PDO, OOP architecture, Docker, and session-based auth #1
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Overview
This PR modernizes the phpblog application by replacing deprecated MySQL functions with PDO, refactoring to object-oriented architecture, adding Docker support, and implementing secure session-based authentication.
Requirements Implemented
Security & Database Improvements
mysql_connect,mysql_select_db,mysql_query,mysql_fetch_assoc,mysql_errorthroughout the codebaseConfiguration Management
config/config.phpfile for centralized configuration management.env.examplefile documenting all required environment variablesAuthentication Enhancement
login.phpto use$_SESSIONinstead of cookieslogout.phpto properly destroy sessionsCode Architecture
src/Database.phpclass for connection management with singleton patternsrc/Posts.phpclass for post operations (CRUD operations)backend.phpto use new OOP structureDependency Management
composer.jsonwith PSR-4 autoloading configurationPhpBlognamespaceContainerization
✅ Created Dockerfile: Sets up PHP 8.x environment with required extensions
pdo_mysqlextension✅ Created docker-compose.yml: Defines complete application stack
Documentation
init.sqlfor database schema setupFiles Changed
New Files
.env.example- Environment variable template.gitignore- Git ignore patterns for PHP projectsDockerfile- Container configuration for PHP applicationdocker-compose.yml- Multi-container orchestrationcomposer.json- Dependency and autoloading configurationconfig/config.php- Centralized configuration managementsrc/Database.php- Database connection classsrc/Posts.php- Posts management classinit.sql- Database initialization scriptREADME.md- Comprehensive setup and usage documentationModified Files
backend.php- Refactored to use OOP and PDOindex.php- Updated to use new Database and Posts classeslogin.php- Migrated to session-based authenticationlogout.php- Updated to destroy sessions properlyadmin/index.php- Updated to use new architectureadmin/add_new_post.php- Updated to use PDO and OOPadmin/new_post.php- Updated to use PDO and OOPTesting
All existing functionality has been preserved:
Deployment
To run the modernized application:
The application will be available at
http://localhost:8080Breaking Changes
None - all existing functionality continues to work as before.
Dependencies
Security Improvements