PHP and MySQL
Standalone tutorials for building secure PHP and MySQL web applications with PDO, validation, sessions and role-based access.
Login Systems
Build secure registration, login, sessions, protected pages and user/admin role-based access with...
Creating a User Database and Table Using SQL
A login system needs a users table that can identify accounts, store password hashes and enforce ...
Secure Password Storage with Password Hashing
Password hashing converts a password into a one-way value suitable for storage. PHP automatically...
Creating a User Registration Form
This standalone registration page accepts a fictional username and password, validates both on th...
Creating a Login Form
This standalone login page validates credentials with PDO, starts a secure session and redirects ...
Using PHP Sessions to Keep Users Logged In
PHP sessions store a small amount of trusted server-side state between requests. A login system c...
Protecting Pages and Preventing Unauthorised Access
A protected page checks authentication on the server before sending restricted content. Hiding a ...
Creating a Logout Page
Logout should remove server-side session data, expire the session cookie and return the user to a...
Adding Role-Based Access Control
Role-based access control allows authenticated users to perform only the actions permitted by the...
Creating a Navigation Menu Based on User Roles
Role-aware navigation shows users the actions available to them. It improves usability, but serve...
Protecting an Admin-Only Data Import Page
A role-based system must enforce permissions on the server. Hiding a link is helpful navigation, ...
PHP and MySQL Foundations
Connect PHP securely to MySQL and implement validated create, read, filter and update operations ...
Connecting PHP to MySQL
A database connection allows PHP to send SQL to MySQL and receive results. Keep the connection in...
Using Prepared Statements
Prepared statements keep user-supplied values separate from SQL instructions. Use them whenever a...
Inserting Validated Form Data
An insert should accept input, validate it, store it with a prepared statement and report a usefu...
Selecting and Displaying Records
A useful output begins with a query and ends with accessible, escaped HTML. Select only required ...
Filtering and Sorting Records
Filters help users reduce a dataset to relevant records. Sorts place those records in a useful or...
Updating Existing Records
An update changes an existing row. The application must identify the row, validate changes and pr...