I havent contributed in many years. You may remember me as ozziemale31 original owner of mobilezonez. Well we are back now. Here is a contribution to people who are in the learning boat. Yeah we've all been there one time or another learning from other scripts. Anyway I have made a tutorial script. for you learners.
A small, readable membership website for learning how a secure PHP/MySQLi site is assembled. It uses no framework.
## Included
- Registration, login and logout
- Arithmetic CAPTCHA at registration
- Password hashing and verification
- MySQLi prepared statements for user-provided values
- CSRF protection and HTML output escaping
- Session cookie protections, ID rotation, idle timeout and absolute timeout
- Basic login throttling
- Member, moderator and administrator roles
- Dashboard and editable profile
- Private messages
- Forum categories, topics and replies
- Admin cPanel for roles and account suspension
- Responsive CSS
- Plain-language guide page
- SQL installer and one-time setup wizard
## Requirements
- PHP 8.1+ (8.2+ recommended)
- MySQL 5.7+ or MariaDB 10.4+
- PHP extensions: mysqli, mbstring, sessions
- HTTPS enabled for live use
## cPanel setup
1. Open cPanel → MySQL Database Wizard.
2. Create a database and a database user.
3. Grant that user ALL PRIVILEGES on the database.
4. Upload and extract this folder into `public_html` or a subfolder.
5. Visit `https://your-domain.example/install.php`.
6. Enter database details and create your first administrator.
7. Sign in using `app.php?page=login`.
8. Delete `install.php` from the server immediately after installation.
9. Check HTTPS is working and confirm `config.php` cannot be downloaded.
The installer runs `database.sql`, creates the first admin account and writes `config.php`. If PHP cannot write the config file, correct folder permissions or create it manually using the settings shown in `install.php`. Do not leave the installer available.
## Files and what they do
- `install.php`: setup wizard and initial admin creation.
- `database.sql`: creates users, login attempts, messages and forum tables.
- `includes/bootstrap.php`: reads config, starts session and opens MySQLi.
- `includes/functions.php`: reusable security, session, CAPTCHA and role helpers.
- `app.php`: simple page router; handles account forms and community features.
- `assets/style.css`: responsive visual design.
## Following a request through login
1. The browser sends a POST request to `app.php?page=login`.
2. `check_csrf()` validates the hidden form token.
3. PHP reads the submitted email and password.
4. A prepared statement looks up the account.
5. `password_verify()` compares the password with its stored hash.
6. The failed attempt is recorded for rate limiting.
7. After a valid login, `session_regenerate_id(true)` changes the session ID.
8. The user ID and session timestamps are stored in the server-side session.
9. The browser is redirected to the dashboard.
## Security is layered — important
No application can honestly guarantee that session hijacking or every attack is impossible. This starter reduces common risks through:
- HttpOnly and SameSite cookies
- Secure cookies when HTTPS is detected
- PHP strict session mode
- Session ID rotation after login and periodically
- Idle and absolute session expiry
- Prepared SQL statements
- CSRF tokens on POST actions
- Escaped HTML output
- Password hashing
- Basic login throttling
- Server-side role checks
Before real public use:
1. Force HTTPS at the web-server/hosting level. Do not rely only on application detection.
2. Keep PHP, MySQL/MariaDB and cPanel patched.
3. Store `config.php` outside the public web root if possible; otherwise verify direct access is denied.
4. Use least-privilege file permissions and regular off-site backups.
5. Add email verification and a secure password-reset workflow with single-use expiring tokens.
6. Add stronger CAPTCHA/anti-bot service if registration abuse occurs.
7. Add moderation, reporting, message blocking, spam protection and audit logs.
8. Add a user session-management page and revoke sessions after password changes or suspension.
9. Have the site reviewed and security-tested before storing sensitive information.
The arithmetic CAPTCHA is deliberately simple for teaching. It is not a sophisticated bot defence. The forum and messaging features are basic examples, not a complete social network.
## Learning convention
Comments explain the purpose of each statement or logical block. The `Tutorials` page explains prepared statements, password hashing, sessions, CSRF, roles, CAPTCHA and output escaping. The code is kept compact enough to read without burying every punctuation mark in a comment.
A small, readable membership website for learning how a secure PHP/MySQLi site is assembled. It uses no framework.
## Included
- Registration, login and logout
- Arithmetic CAPTCHA at registration
- Password hashing and verification
- MySQLi prepared statements for user-provided values
- CSRF protection and HTML output escaping
- Session cookie protections, ID rotation, idle timeout and absolute timeout
- Basic login throttling
- Member, moderator and administrator roles
- Dashboard and editable profile
- Private messages
- Forum categories, topics and replies
- Admin cPanel for roles and account suspension
- Responsive CSS
- Plain-language guide page
- SQL installer and one-time setup wizard
## Requirements
- PHP 8.1+ (8.2+ recommended)
- MySQL 5.7+ or MariaDB 10.4+
- PHP extensions: mysqli, mbstring, sessions
- HTTPS enabled for live use
## cPanel setup
1. Open cPanel → MySQL Database Wizard.
2. Create a database and a database user.
3. Grant that user ALL PRIVILEGES on the database.
4. Upload and extract this folder into `public_html` or a subfolder.
5. Visit `https://your-domain.example/install.php`.
6. Enter database details and create your first administrator.
7. Sign in using `app.php?page=login`.
8. Delete `install.php` from the server immediately after installation.
9. Check HTTPS is working and confirm `config.php` cannot be downloaded.
The installer runs `database.sql`, creates the first admin account and writes `config.php`. If PHP cannot write the config file, correct folder permissions or create it manually using the settings shown in `install.php`. Do not leave the installer available.
## Files and what they do
- `install.php`: setup wizard and initial admin creation.
- `database.sql`: creates users, login attempts, messages and forum tables.
- `includes/bootstrap.php`: reads config, starts session and opens MySQLi.
- `includes/functions.php`: reusable security, session, CAPTCHA and role helpers.
- `app.php`: simple page router; handles account forms and community features.
- `assets/style.css`: responsive visual design.
## Following a request through login
1. The browser sends a POST request to `app.php?page=login`.
2. `check_csrf()` validates the hidden form token.
3. PHP reads the submitted email and password.
4. A prepared statement looks up the account.
5. `password_verify()` compares the password with its stored hash.
6. The failed attempt is recorded for rate limiting.
7. After a valid login, `session_regenerate_id(true)` changes the session ID.
8. The user ID and session timestamps are stored in the server-side session.
9. The browser is redirected to the dashboard.
## Security is layered — important
No application can honestly guarantee that session hijacking or every attack is impossible. This starter reduces common risks through:
- HttpOnly and SameSite cookies
- Secure cookies when HTTPS is detected
- PHP strict session mode
- Session ID rotation after login and periodically
- Idle and absolute session expiry
- Prepared SQL statements
- CSRF tokens on POST actions
- Escaped HTML output
- Password hashing
- Basic login throttling
- Server-side role checks
Before real public use:
1. Force HTTPS at the web-server/hosting level. Do not rely only on application detection.
2. Keep PHP, MySQL/MariaDB and cPanel patched.
3. Store `config.php` outside the public web root if possible; otherwise verify direct access is denied.
4. Use least-privilege file permissions and regular off-site backups.
5. Add email verification and a secure password-reset workflow with single-use expiring tokens.
6. Add stronger CAPTCHA/anti-bot service if registration abuse occurs.
7. Add moderation, reporting, message blocking, spam protection and audit logs.
8. Add a user session-management page and revoke sessions after password changes or suspension.
9. Have the site reviewed and security-tested before storing sensitive information.
The arithmetic CAPTCHA is deliberately simple for teaching. It is not a sophisticated bot defence. The forum and messaging features are basic examples, not a complete social network.
## Learning convention
Comments explain the purpose of each statement or logical block. The `Tutorials` page explains prepared statements, password hashing, sessions, CSRF, roles, CAPTCHA and output escaping. The code is kept compact enough to read without burying every punctuation mark in a comment.