This project is a simple PHP API for user registration and login. It is structured using an MVC pattern with a custom routing system.
-
Clone the repository:
git clone https://github.com/chamasab/php_mvc_login_and_register.git cd php_mvc_login_and_register
-
Install Composer dependencies: Ensure you have Composer installed. Then, run:
composer install
-
Set up your environment:
- Create a MySQL database for the project.
- Update the database credentials in
src/config/config.php
.
-
Run the PHP built-in server:
php -S localhost:8000 -t public
/php_mvc_login_and_register
│
├── /public
│ └── index.php
│
├── /src
│ ├── /controllers
│ │ └── UserController.php
│ ├── /models
│ │ └── UserModel.php
│ ├── /routes
│ │ └── web.php
│ ├── /core
│ │ ├── Router.php
│ │ ├── Controller.php
│ │ ├── Model.php
│ │ └── View.php
│ ├── /middlewares
│ │ └── AuthMiddleware.php
│ ├── /helpers
│ │ └── ResponseHelper.php
│ └── /config
│ └── config.php
│
├── /logs
│ └── app.log
│
└── composer.json
Update the database configuration in src/config/config.php
:
<?php
return [
'db' => [
'host' => 'localhost',
'dbname' => 'your_database',
'user' => 'your_username',
'pass' => 'your_password'
],
'log_file' => __DIR__ . '/../../logs/app.log'
];
?>
-
Register
- URL: /register
- Method: POST
- Body: JSON
{ "name": "John Doe", "email": "[email protected]", "password": "securepassword" }
- Response
{ "message": "User registered successfully" }
-
Login
-
URL: /login
-
Method: POST
-
Body: JSON
-
Request
{ "email": "[email protected]", "password": "securepassword" }
-
Response
{ "message": "Login successful", "user": { "id": 1, "name": "John Doe", "email": "[email protected]", "logged_at": "2024-07-18 12:34:56" } }
-