A simple PHP authentication application featuring user registration, login, and protected dashboard functionality. This project is ideal for learning and quick prototyping of web authentication using PHP and MySQL.
-
Clone the repository
git clone https://github.com/Ali-Amir-code/auth_app_t2.git cd auth_app_t2 -
Configure the Database
- Create a database named
auth_dbin MySQL (e.g., via XAMPP or phpMyAdmin). - Create a table named
users:CREATE TABLE users ( id INT AUTO_INCREMENT PRIMARY KEY, username VARCHAR(255) NOT NULL, email VARCHAR(255) NOT NULL UNIQUE, password VARCHAR(255) NOT NULL );
- Update
config/db.phpif you use different DB credentials.
- Create a database named
-
Run the Application
- Place the project in your web server directory (e.g.,
htdocsfor XAMPP). - Navigate to
http://localhost/auth_app_t2/index.phpin your browser.
- Place the project in your web server directory (e.g.,
auth_app_t2/
βββ config/
β βββ db.php # Database connection
βββ includes/
β βββ functions.php # Utility functions (e.g., sanitization, login checks)
βββ public/
β βββ css/
β β βββ styles.css # Frontend styles
β βββ dashboard.php # Protected dashboard (after login)
β βββ logout.php # Logout handler
β βββ register.php # User registration page
βββ index.php # Login page & entry point
-
Registration:
- Users sign up via
public/register.php. - Input is sanitized, email uniqueness is checked, and passwords are hashed before storing in the database.
- Users sign up via
-
Login:
- Users log in via
index.php. - Credentials are validated; password verification uses PHPβs
password_verify().
- Users log in via
-
Session Management:
- Upon successful login, PHP sessions store user ID and username.
- Protected routes like
public/dashboard.phpuse session checks (ensure_logged_in()).
-
Logout:
public/logout.phpdestroys the session and redirects to login.
- Database Connection (
config/db.php):
Uses MySQLi to connect to a local database. Error handling for connection issues is implemented. - Utility Functions (
includes/functions.php):sanitize(): For safe input handling.redirect(): For navigation.is_logged_in()&ensure_logged_in(): For session-based access control.
- Frontend (
public/css/styles.css):- Modern gradient background and card layout.
- Responsive forms for login and registration.
- Security:
- Inputs are sanitized; passwords are hashed.
- Email uniqueness is enforced during registration.
- Customization:
- You can expand the dashboard, add password reset, or introduce email verification as needed.
- Stack:
- PHP, MySQL, HTML/CSS.
For questions or feedback, open an issue on GitHub.



