Skip to content

zainabreh/blog_website_php

Repository files navigation

PHP Blog Management System

A complete Blog Management System built using PHP and MySQL, featuring user authentication, blog CRUD operations, dashboard management, and email notifications.
This project demonstrates real-world backend workflows commonly used in PHP-based web applications.


🔧 Features

  • User registration and login
  • Secure session-based authentication
  • Blog creation, update, and deletion
  • Dashboard for managing blogs
  • Email notification using PHPMailer
  • File upload support
  • Database-driven application

🛠 Technologies Used

  • PHP
  • MySQL
  • PHPMailer
  • Composer
  • HTML
  • CSS
  • Bootstrap
  • XAMPP (Local Development)

📂 Project Structure (Key Files)

  • index.php – Homepage / Blog listing
  • register.php – User registration
  • login.php – User authentication
  • dashboard.php – User dashboard
  • createBlog.php – Create blog post
  • updateBlog.php – Update blog post
  • deleteBlog.php – Delete blog post
  • database.php – Database connection
  • process.php – Email processing
  • vendor/ – Composer dependencies

🔐 Authentication & Sessions

📝 User Registration (Sample Code)

if (isset($_POST['register'])) {
    $name  = $_POST['fullname'];
    $email = $_POST['email'];
    $pass  = password_hash($_POST['password'], PASSWORD_DEFAULT);

    $query = "INSERT INTO users (fullname, email, password) VALUES ('$name', '$email', '$pass')";
    mysqli_query($conn, $query);
}

🔑 User Login with Session

session_start();

if (password_verify($password, $user['password'])) {
    $_SESSION['id'] = $user['id'];
    $_SESSION['email'] = $user['email'];
    header("Location: dashboard.php");
    exit;
}

📊 Dashboard Access Control

session_start();

if (!isset($_SESSION['id'])) {
    header("Location: login.php");
    exit;
}

✔ Ensures only authenticated users can access the dashboard.


✏️ Update Blog

$query = "DELETE FROM blogs WHERE id='$id'";
mysqli_query($conn, $query);

❌ Delete Blog

$query = "DELETE FROM blogs WHERE id='$id'";
mysqli_query($conn, $query);

📧 Email Notification (PHPMailer)

PHPMailer is installed using Composer.

composer require phpmailer/phpmailer

Sample Email Sending Code

PHPMailer is installed using Composer.

use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;

require "vendor/autoload.php";

$mail = new PHPMailer(true);

$mail->isSMTP();
$mail->Host = 'smtp.gmail.com';
$mail->SMTPAuth = true;
$mail->Username = 'your_email@gmail.com';
$mail->Password = 'your_app_password';
$mail->SMTPSecure = PHPMailer::ENCRYPTION_STARTTLS;
$mail->Port = 587;

$mail->setFrom('test@test.com', 'Blog System');
$mail->addAddress($email);
$mail->Subject = 'Blog Notification';
$mail->Body = 'Your blog has been published successfully';

$mail->send();

📚 Learning Outcomes

  • Building authentication systems in PHP
  • Session management and access control
  • CRUD operations with MySQL
  • Integrating PHPMailer using Composer
  • Structuring a real-world PHP project
  • Writing maintainable backend logic

📌 Notes

  • This project is built for learning and practice purposes
  • Uses local SMTP configuration for testing
  • Can be improved by:
    • Using prepared statements (SQL Injection prevention)
    • Adding role-based access
    • Implementing pagination
    • Adding .env configuration for credentials

🚀 Future Improvements

  • PDO implementation
  • Admin role management
  • Comment system
  • Email verification on registration
  • Password reset functionality

About

A simple PHP blog management system with user authentication and session-based access. Includes login/register, dashboard, CRUD blog features, and email notifications. Built using core PHP, MySQL, and PHPMailer for learning and practice purposes.

Topics

Resources

Stars

Watchers

Forks

Contributors

Languages