Interactive roadmap
PHP roadmap
Designed for complete beginners to learn server-side web development. By the end, you will be able to build dynamic websites and connect them to secure databases.
- 1
Basic PHP Syntax
0 of 3 done
Learn how to write and run your very first PHP scripts.
Take your time with syntax basics; writing small scripts every day helps the logic stick in your mind. - 2
Functions and Arrays
0 of 3 done
Organise your code into reusable blocks and manage collections of data.
Breaking your code into small, reusable functions makes large projects much easier to read and maintain. - 3
Forms and User Input
0 of 3 done
Handle user input safely from web browser forms.
Always treat user input with caution; validating and cleaning data protects your site from broken states. - 4
Object-Oriented PHP
0 of 3 done
Build structured applications using classes and objects.
Object-oriented programming helps model real-world concepts cleanly, making large applications much easier to scale. - 5
Databases and Packages
0 of 3 done
Connect PHP to databases and manage external packages.
Always use prepared statements when interacting with databases to keep your application secure against attacks.
Learn it all, with a tutor that never sleeps
Every topic links to LevelUp lessons, practice exercises and the 24/7 AI Tutor. Your progress updates as you master lessons.
Every topic explained
Step 1: Basic PHP Syntax
- Understand how to embed PHP inside HTML and output text to the browser.PHP Manual (PHP.net)
Read more
PHP tags tell your web server where to run server-side code before sending plain HTML to the browser. You wrap your instructions inside special opening and closing symbols so the server knows what to execute.
Think of it like a script behind a theatre curtain. The audience only sees the final performance, which is the HTML output, while the actors backstage do the heavy lifting.
Mastering output is vital because it is your main way to display dynamic content to users.
- Use special opening and closing tags for PHP code
- The echo command displays text on the screen
- Code runs on the server before reaching the browser
- Store different kinds of data using variables and basic types like strings and numbers.
Read more
Variables act as labelled containers for storing information like text, numbers, or true-false values. In PHP, every variable name starts with a dollar sign to show it is a placeholder.
Imagine a box in your hallway labelled keys or coins. You can put items inside, swap them out, or check what is inside whenever you need it.
Understanding data types ensures your application handles math correctly and displays text without unexpected formatting errors.
- Variables always begin with a dollar sign symbol
- Strings hold text, while integers hold whole numbers
- Data types determine how PHP processes your stored values
- Make decisions in your code using if statements and repeat tasks with loops.
Read more
Control flow lets your program make choices and repeat actions based on changing conditions. If statements check whether a condition is true, while loops handle repetitive tasks automatically.
Think of a traffic light deciding whether cars must stop or go, or a factory machine repeating a packaging step ten times.
These tools form the logic engine of your website, allowing it to respond dynamically to user actions.
- Use if and else statements for conditional decisions
- Loops like while and for automate repetitive tasks
- Conditions rely on comparison operators like greater than
Step 2: Functions and Arrays
- Store lists of related items using standard and associative arrays.
Read more
Arrays let you store multiple items inside a single variable instead of creating dozens of separate ones. Standard arrays use numbered indexes, while associative arrays use named keys for clarity.
Think of a shopping list with numbered items, or a contact card where each detail has a specific label like email or phone.
Arrays are essential for managing lists of database records or form inputs efficiently.
- Standard arrays use zero-based numeric indexes
- Associative arrays use named keys to store values
- Foreach loops make walking through array items simple
- Create your own functions to avoid repeating code and keep projects tidy.
Read more
Custom functions are blocks of reusable code designed to perform a specific task when called. Instead of rewriting the same logic, you write it once and reuse it across your project.
Think of a kitchen appliance like a blender that you load with ingredients whenever you need a smoothie, rather than chopping everything by hand each time.
Writing functions keeps your codebase clean and reduces bugs.
- Define functions using the function keyword
- Pass data into functions using input parameters
- Use return to send the final result back
- (optional)
- Learn how variable scope works and split your code across multiple files.
Read more
Variable scope defines where in your code a variable can be accessed or modified. File includes let you split your project into modular parts like headers and footers.
Think of keeping your personal journal locked in a private drawer rather than posted on the public noticeboard.
Splitting files keeps code organised and prevents massive, confusing single-file scripts.
- Functions have local scope for their internal variables
- Use require or include to pull in external files
- Modular code improves collaboration and project organisation
Step 3: Forms and User Input
- Receive and process data sent from HTML forms using superglobal arrays.
Read more
GET and POST are superglobal arrays that capture information sent from user browsers to your server. GET displays parameters in the URL, while POST hides them in the HTTP request body.
Think of GET as sending a postcard where details are visible, and POST as mailing a sealed envelope for sensitive data.
Handling requests correctly is the bridge between static web pages and interactive applications.
- The superglobal stores form inputs safely
- GET is suitable for search queries and pagination
- POST is required for passwords and form submissions
- Clean and validate user input to prevent errors and bad data.
Read more
Sanitising input means cleaning and validating data submitted by users before processing or storing it. This removes unwanted characters and checks if formats match expectations.
Think of a security guard checking ID badges and screening bags at an event entrance to keep everyone safe.
This step prevents errors, broken layouts, and security vulnerabilities across your application.
- Never trust raw user input directly
- Use built-in filter functions to clean text
- Validate email formats before database storage
- (optional)
- Remember users across multiple page visits using cookies and server sessions.
Read more
Cookies store small data files directly on the user browser, while sessions store temporary data securely on the server. Both help remember user states across page clicks.
Think of a cookie as a stamp on your hand for re-entry, and a session as a VIP guest list held at the venue desk.
These tools are essential for features like login systems and shopping baskets.
- Start sessions with the session_start function
- Cookies live on the client browser until expiry
- Sessions persist data securely on the server
Step 4: Object-Oriented PHP
- Create blueprints for your data and instantiate objects from them.
Read more
Classes act as blueprints, while objects are the individual instances created from those blueprints. They bundle related data and functions together into tidy units.
Think of a class as an architectural blueprint for a house, and objects as the physical houses built from that plan.
This approach keeps your code modular and mirrors how we think about objects in the real world.
- Classes define properties and methods
- Create objects using the new keyword
- Each object maintains its own unique property values
- Initialise object properties automatically when objects are created.
Read more
Constructors are special setup methods that run automatically when an object is instantiated. The keyword refers to the current object instance.
Think of setting up a new smartphone when you first turn it on, filling in your language and timezone preferences immediately.
This ensures your objects are always properly configured from the moment they are created.
- The constructor method is named construct
- Use this to access current object properties
- Pass startup arguments directly into the constructor
- (optional)
- Share common functionality between classes using inheritance.
Read more
Inheritance allows a new class to adopt properties and methods from an existing parent class, avoiding code duplication. It builds hierarchical relationships.
Think of an electric car inheriting basic vehicle traits like wheels and steering from a general car blueprint.
This promotes code reuse and helps organise complex software architectures.
- Use the extends keyword for class inheritance
- Child classes inherit parent methods and properties
- Child classes can also override parent behaviour
Step 5: Databases and Packages
- Connect your PHP application to a database securely using PDO.
Read more
PDO provides a secure, consistent interface for connecting PHP applications to various database systems. It handles the connection layer so you can run queries safely.
Think of a universal power adapter that lets you plug your devices into wall sockets anywhere in the world.
Mastering database connections is the key to building data-driven websites that persist information permanently.
- PDO stands for PHP Data Objects
- It supports multiple database types like MySQL
- Connection errors are handled using try-catch blocks
- Protect your database from malicious input using prepared statements.
Read more
Prepared statements separate SQL query structure from user data, neutralising malicious input attempts. The database treats input strictly as data, never as executable code.
Think of a bank teller sliding forms through a secure glass slot rather than letting customers handle the cash drawer directly.
This is the single most important defence against database injection attacks.
- Never concatenate user input directly into SQL
- Use placeholders like question marks in queries
- Bind parameters safely before executing statements
- (optional)
- Install and manage third-party libraries using the Composer package manager.Composer (GetComposer.org)
Read more
Composer is the standard dependency manager for PHP, letting you install and update third-party libraries easily. It saves you from writing every utility from scratch.
Think of visiting an app store to download pre-built tools rather than building a calculator or calendar yourself.
Using packages speeds up development and connects you to the wider PHP ecosystem.
- Composer manages project libraries and autoloading
- Package definitions live in composer json files
- Install packages via command line tools