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
- Open cPanel → MySQL Database Wizard.
- Create a database and a database user.
- Grant that user ALL PRIVILEGES on the database.
- Upload and extract this folder into
public_htmlor a subfolder. - Visit
https://your-domain.example/install.php. - Enter database details and create your first administrator.
- Sign in using
app.php?page=login. - Delete
install.phpfrom the server immediately after installation. - Check HTTPS is working and confirm
config.phpcannot 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
- The browser sends a POST request to
app.php?page=login. check_csrf()validates the hidden form token.- PHP reads the submitted email and password.
- A prepared statement looks up the account.
password_verify()compares the password with its stored hash.- The failed attempt is recorded for rate limiting.
- After a valid login,
session_regenerate_id(true)changes the session ID. - The user ID and session timestamps are stored in the server-side session.
- 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:
- Force HTTPS at the web-server/hosting level. Do not rely only on application detection.
- Keep PHP, MySQL/MariaDB and cPanel patched.
- Store
config.phpoutside the public web root if possible; otherwise verify direct access is denied. - Use least-privilege file permissions and regular off-site backups.
- Add email verification and a secure password-reset workflow with single-use expiring tokens.
- Add stronger CAPTCHA/anti-bot service if registration abuse occurs.
- Add moderation, reporting, message blocking, spam protection and audit logs.
- Add a user session-management page and revoke sessions after password changes or suspension.
- 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.