A simple authentication system with React frontend and PHP backend using session-based authentication.
- Frontend: React (functional components + hooks)
- Backend: PHP (with session handling)
- Data Storage: users.json (with hashed passwords)
- Authentication: Session-based
project-root/
├── backend/
│ ├── users.json # Sample users with hashed passwords
│ ├── login.php # Handles login, session creation
│ ├── dashboard.php # Protected route, shows Welcome {user}
│ ├── logout.php # Ends session
│ └── .htaccess # CORS configuration
├── frontend/
│ ├── public/
│ │ └── index.html
│ ├── src/
│ │ ├── pages/
│ │ │ ├── Login.js
│ │ │ └── Dashboard.js
│ │ ├── App.js
│ │ └── index.js
│ └── package.json
├── .gitignore
└── README.md
-
Navigate to backend directory:
cd backend
-
Start PHP development server:
php -S localhost:8000
-
Backend will be accessible at: http://localhost:8000
-
Navigate to frontend directory:
cd frontend
-
Install dependencies:
npm install
-
Start React development server:
npm start
-
Frontend will be accessible at: http://localhost:3000
The following test users are available in users.json
:
Password | |
---|---|
test@example.com | password |
admin@example.com | password |
- Login Form: Email and password authentication
- Session Management: PHP sessions for user state
- Protected Routes: Dashboard requires authentication
- Error Handling: Invalid credentials display error message
- Logout: Clear session and redirect to login
- Password Security: Passwords hashed using
password_hash()
- Passwords are hashed using PHP's
password_hash()
function - Sessions are properly managed with
session_start()
- CORS headers configured for cross-origin requests
- Input validation on both frontend and backend