This project is a simple PHP web template that demonstrates how to create a user authentication system using PDO
with MySQL
. It includes registration, login, password hashing (using bcrypt
), and session management. It also uses the XAMPP
local development environment to run the project.
User Registration
: Allows users to create an account with a full name, email, and password.User Login
: Users can log in with their email and password.User Profile
: Users can change their bio, email, and full name.User Settings
: Users can change their passwords and delete their accounts.Password Hashing
: Passwords are securely stored in the database usingbcrypt
hashing.Session Management
: Once logged in, the user session is maintained until they log out.Remember Me
: Users can opt to be remembered across sessions (using cookies).MySQL Database Integration
: The project integrates with MySQL to store user information securely.
Before setting up the project, ensure you have the following software installed:
XAMPP
: A local server environment that includes Apache, MySQL, and PHP.- Download XAMPP: https://www.apachefriends.org/download.html
- Make sure Apache and MySQL are running in XAMPP.
-
Clone or download the repository to your local machine.
git clone https://github.com/AlphaX50/php-web-template.git
- Open your XAMPP installation folder (typically located in
C:\xampp\
on Windows). - Copy the project folder and place it in the htdocs folder (located in C:\xampp\htdocs).
- Open phpMyAdmin by navigating to
http://localhost/phpmyadmin/
in your web browser. - Create a new database named
template_PHP_web
. - Use the following SQL query to create the necessary table for storing users:
CREATE TABLE users (
id INT AUTO_INCREMENT PRIMARY KEY,
full_name VARCHAR(255) NOT NULL,
email VARCHAR(255) NOT NULL UNIQUE,
password VARCHAR(255) NOT NULL,
remember_token VARCHAR(255) DEFAULT NULL,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
bio TEXT DEFAULT NULL,
profile_picture VARCHAR(255) DEFAULT NULL,
role TINYINT(1) DEFAULT 0
);
- In the
config.php
file, update the database connection details to match your local MySQL setup:
<?php
// Set database connection setting
$host = 'localhost'; // MySQL server address (usually 'localhost')
$dbname = 'template_PHP_web'; // Database name
$username = 'root'; // MySQL username (default is 'root' on XAMPP)
$password = ''; // MySQL password (default empty on XAMPP)
$charset = 'utf8mb4'; // Character set to use
$dsn = "mysql:host=$host;dbname=$dbname;charset=$charset";
$options = [
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC,
PDO::ATTR_EMULATE_PREPARES => false,
];
try {
$pdo = new PDO($dsn, $username, $password, $options);
} catch (\PDOException $e) {
die("Connection failed: " . $e->getMessage());
}
?>
- Start Apache and MySQL from the XAMPP control panel.
- Open a browser and navigate to
http://localhost/project-folder
(replace project-folder
with the name of your project directory). - You should be able to see the project running locally.
- Go to the
signup.php
page and register a new user. - Enter a full name, email, and a password.
- Once the registration is successful, you will be redirected to the login page.
If you encounter any issues or need assistance, feel free to reach out to me on Discord: alphax50.
Login.php
Signup.php
Index.php
Profil.php
Settings.php