Server Side Language

PHP Complete Tutorial

This page is fully PHP-focused. Learn syntax, backend basics, forms, database integration, sessions, and security with practical examples.

Beginner to Intermediate Backend Ready 18 Chapters
Chapter 00

PHP Live Lab

Edit PHP code and click Run. This lab simulates common PHP output from echo and simple variables.

php-lab.php
Chapter 01

What is PHP?

PHP is a server-side scripting language used to build dynamic websites and web applications. It runs on the server and outputs HTML to the browser.

Use PHP when you need login systems, forms, CRUD operations, APIs, sessions, and database-driven content.

Tip: PHP works great with Apache + MySQL in XAMPP.
intro.php
Chapter 02

Setup

Create a `.php` file in your XAMPP `htdocs` folder and open it through `http://localhost/yourfile.php`.

setup.php
Chapter 03

PHP Syntax

PHP code is written inside `<?php ... ?>`. Statements usually end with semicolons.

syntax.php
Chapter 04

Variables

Variables in PHP start with `$`. PHP is dynamically typed, so you do not declare data types explicitly.

variables.php
Chapter 05

Arrays

PHP supports indexed arrays, associative arrays, and multidimensional arrays.

arrays.php
Chapter 06

Conditions

Use `if`, `elseif`, `else`, and `switch` to branch logic.

conditions.php
Chapter 07

Loops

PHP supports `for`, `while`, `do...while`, and `foreach` loops.

loops.php
Chapter 08

Functions

Create reusable blocks with `function`, optional type hints, and return values.

functions.php
Chapter 09

Handling Forms

Use `$_GET` and `$_POST` superglobals to receive form data from users.

forms.php
Chapter 10

MySQL with PDO

Use PDO prepared statements for secure and clean database access.

mysql.php
Chapter 11

OOP in PHP

PHP supports classes, objects, inheritance, interfaces, and traits.

oop.php
Chapter 12

Sessions

Sessions help store logged-in user state across multiple pages.

sessions.php
Chapter 13

Security Basics

Always validate input, escape output, and use prepared statements to prevent common vulnerabilities.

Key practices: use `password_hash`, `password_verify`, `htmlspecialchars`, CSRF tokens, and strict input validation on server side.

Tip: Never trust browser input directly, validate everything in PHP.
security.php
Chapter 14

Includes and Requires

Use `include` and `require` to reuse header, footer, config, and helper files across pages.

includes.php
Chapter 15

File Uploads

Validate file type and size before moving uploaded files to a safe directory.

uploads.php
Chapter 16

JSON and APIs

Return API responses as JSON and set the right `Content-Type` header in PHP.

json-api.php
Chapter 17

Authentication Basics

Use password hashing and session checks to build secure login systems.

auth.php
Chapter 18

Error Handling and Logging

Catch runtime issues and log them to files instead of showing sensitive errors to users.

errors.php