Web Nerdism w/ PHP 101
How the web works, taught with PHP.
PHP?! What? Yes. It isn't fashionable, and it doesn't need to be. It runs on more than 70 percent of the websites whose server-side language W3Techs can see, WordPress and Wikipedia among them. It's free, it's fast enough, it's been quietly getting better for thirty years, and it's still the shortest path from "I wrote some code" to "it's on a web page." What you learn here carries over to whatever you use next.
Short lessons, one page each, then small projects that use them. It starts before PHP, with how two computers talk at all, and it ends with you building things that hold up when someone tries to break them.
It's being written now, a lesson at a time. Linked lessons are up; the rest are on their way.
Before You Start: Tools
Not lessons, just the few things you set up once and come back to. Everything else in the course runs in a container, so the only thing you install is Docker.
- Reading the Examples
- The Terminal
- Package managers: Homebrew or apt, whichever is yours
- Docker
- Git
- Your Editor
- Your Browser's Developer Tools
- Reading Logs
- Composer, in a Container
Also: Vocabulary, every web word the course uses, defined.
Basics: How the Web Works
- Client/Server
- Anatomy of a URL
- DNS
- HTTP, HTTPS and TLS
- Request and Response
- Content Types
- Cookies
- Query Strings
- Forms
- What's in the Middle
Web Server Basics
- Document Root
- Access and Error Logs
- How PHP Actually Runs: nginx and PHP-FPM
- Configuration and the Environment
PHP Basics
- PHP Files, Escaping into PHP, and phpinfo()
- Documentation: php.net
- Output
- Variables, Types and strict_types
- Operators
- Types of Types
- Scope
- Strings
- Text and UTF-8
- Arrays
- Functions
- Errors and the Error Log
- Includes
- Working with Files
- Working with a Database: PDO and Prepared Statements
Database
- SQL
- Creating Tables
- Relating Tables: Keys and Foreign Keys
- Normalization
- Indexes
- Character Sets and Collation
- Inserting Data
- Selecting Data
- Updating Data
- Deleting Data
- Transactions
- Migrations
PHP Not So Basics
- Sessions
- Output Buffering
- Caching
- Sending a File
- Naming Things
- Classes and Objects
- Abstract Classes
- Interfaces
- Autoloading with Composer and PSR-4
- Exceptions and Try/Catch
- Constants, Static Variables and Functions
- Modern PHP
- Magic Methods
- Dependency Injection
- Two-Dollar Test Harnesses
- Testing
Security
Every lesson here starts by breaking it, then fixes it.
- Never Trust Input
- SQL Injection
- XSS and Escaping Output
- CSRF
- Passwords: password_hash() and Nothing Else
- Sessions and Cookie Flags
- Rate Limiting
- Secrets Out of Code
- File Uploads
- Don't Touch Cards
- Security Headers
- Your Dependencies Are Your Code Too
Various Web Technologies
- HTML
- CSS
- JavaScript
- fetch() and AJAX
- JSON
- CORS
- CSV
- HTMX
Projects
Small things to build, in order, each using the lessons before it. The ones where a classic mistake lives come with a "Break it" section: build it the naive way, attack your own copy, then fix it.
- Home Page
- View Source Link
- Useful Includes
- Layout
- Logging
- Cookies
- Sending Email
- Contact Form
- Form Validation
- Redirecting
- Guestbook
- Sessions
- Protected Page
- Something Database-y
- Signup Form
- Login Form
- Profile Page
- Change Password Form
- HTTP Authentication
- Log Viewer
- Translation
- Content Management System
- Blog
- Comments
- Caching
- PHP on the Command Line
- Cron Jobs
- Queues
- Newsletter
- Store Front
- Shopping Cart
- Checkout
- Taking a Payment with Stripe Checkout
- Exporting Data
- Affiliate Program
- REST API
- API Client
Style
- Coding Standards
- Good Variable Names
- Magic Numbers in Code
- Declaring Symbols vs. Causing Changes
- Defensive Programming
- DRY
- Return Early
- Single Point of Return
- Expressive HTTP Response Codes, and When Not to Be
Various Patterns
- Separating Concerns
- MVC
- Single Point of Entry
- CRUD
- Model, Table, Mapper
- REST
- Middleware and Pipelines
- Singletons
- Factories
- Observers
Convictions
- Code should be boring
- The three virtues
- Be liberal in what you accept, strict in what you output
- Code should be written to be read by humans, and only incidentally run on computers
- Most PHP web/db programming problems are really SQL database problems
- If you have to run the whole stack to test one thing, the thing is too big
Rants
- Why PHP Sucks but Isn't So Bad After All
- PHP Doesn't Suck!
- Why Magic Methods Are Bad
- Why Inheritance Annoys Me
- Why Hungarian Is Bad
- Why Hungarian for Apps Isn't So Bad