HTML and CSS make a page. JavaScript makes it react in the browser. PHP runs on the server and builds the page, reads the form, checks the password, talks to the database and sends the result back.
This course teaches modern PHP from the first line of code to a small working CMS. Each lesson explains one idea in plain language, shows short code with its expected output, points out the mistakes people usually make and ends with a small practice task.
What is PHP, and where does it run?
PHP is a server-side programming language. When someone opens a page, the web server runs your PHP code, and the browser receives only the result, usually HTML. Start with What Is PHP? and How PHP Works.
PHP code does not run in the browser, so the examples in this course do not have a Try it button. Each PHP example shows the code and the output you should see, and Running Your First PHP File shows how to run it on your own computer in a couple of minutes.
PHP, HTML, CSS and JavaScript
The four work together. PHP builds the HTML, CSS styles it and JavaScript adds behaviour in the browser. If you want a refresher on the other three, see the HTML course, the CSS course and the JavaScript course.
Modern PHP, not PHP 5
Many tutorials still teach PHP the way it was written fifteen years ago. This course teaches how PHP is written today: typed parameters and return values, match, named arguments, constructor property promotion, enums, readonly properties, namespaces and Composer. PHP Versions explains what changed from PHP 5 to PHP 8.
What you will be able to do
By the end of the course you will be able to:
- Write PHP with variables, conditions, loops, functions and arrays.
- Handle forms, validate input and keep users logged in with sessions.
- Read and write files and handle errors with exceptions.
- Write object-oriented PHP with classes, interfaces and traits.
- Use PHP 8 features such as enums,
match, readonly properties and attributes. - Organise code with namespaces and install packages with Composer.
- Connect to MySQL with PDO and build create, read, update and delete pages.
- Build registration and login with safe password hashing.
- Protect an application against SQL injection, XSS, CSRF and unsafe uploads.
- Work with JSON and APIs and structure a small PHP project.
- Build 11 projects, from a calculator to a mini CMS.
Before you start
You need a computer, a code editor and PHP. No programming experience is needed. A little HTML helps. Installing PHP and PHP Development Environment walk you through the setup.
How to use this course
- Go in order. Lessons build on earlier ones. Use the chapter list on the left (or the course button on a phone).
- Run the code yourself. Type the examples instead of pasting them, then change them and see what happens.
- Compare with the output. The output block under each example is what the code prints.
- Do the exercises. Try each one before you open the solution.
- Read the warnings. Security notes are marked clearly, and the security chapter explains the attacks in detail.