Master the language that powers 77% of websites.
// PHP HISTORY
Created by Rasmus Lerdorf in 1994, PHP (Hypertext Preprocessor) started as a set of Common Gateway Interface (CGI) binaries written in C. Today, it powers WordPress, Laravel, Drupal, and millions of dynamic websites worldwide.
// WHY PHP MATTERS
PHP is the backbone of the modern web. It seamlessly integrates with HTML, connects to databases, handles form data, and creates dynamic content. With PHP 8's modern features like JIT compilation and attributes, it's more powerful than ever.
12 lessons • Server-side mastery
Server-side scripting for web development
BeginnerStore and manipulate data values
BeginnerPerform calculations and comparisons
BeginnerMake decisions with if/else statements
BeginnerWork with indexed and associative arrays
BeginnerManipulate text with built-in functions
BeginnerHandle GET and POST data securely
IntermediateMaintain state across page requests
IntermediateConnect to MySQL with PDO.
IntermediateRead, write, and upload files.
IntermediateClasses, objects, and inheritance.
AdvancedPrevent XSS, SQL injection, hash passwords.
AdvancedPHP was created by Rasmus Lerdorf in 1994 as a set of CGI binaries written in C. Today, it powers 77% of all websites with known server-side programming, including WordPress, Facebook, and Wikipedia.
PHP is the backbone of the modern web. It seamlessly integrates with HTML, connects to databases, handles form data, and creates dynamic content. With PHP 8's modern features like JIT compilation and attributes, it's more powerful than ever.
From small personal blogs to enterprise-scale applications, PHP scales to meet your needs. The massive ecosystem of frameworks like Laravel, Symfony, and CodeIgniter makes rapid development a reality.
The web runs on PHP. Own it.
PHP (PHP: Hypertext Preprocessor) is a server-side scripting language designed specifically for web development. It runs on the server, generating HTML that is sent to the client.
PHP code must be enclosed in opening and closing tags:
1. PHP stands for _____ Preprocessor.
Hint: H-T-M-L related
2. PHP runs on the _____.
Hint: Not client
3. echo is a PHP _____.
Hint: Not a function
4. The opening PHP tag is _____.
Hint: Three characters
5. PHP is _____ source.
Hint: Free to use
6. WordPress uses PHP as its _____.
Hint: Programming language
7. PHP code ends with _____.
Hint: Two characters
8. php --_____ shows version info.
Hint: Command line
Variables in PHP start with a dollar sign ($) followed by the variable name. Variables are case-sensitive.
PHP supports variable variables - using one variable's value as another variable's name:
1. Variables start with _____.
Hint: Dollar sign
2. Strings can use _____ quotes.
Hint:
3. gettype() returns the _____.
Hint: Type of variable
4. (int) casts to _____.
Hint: Whole number
5. $$foo is a _____ variable.
Hint: Dynamic name
6. Heredoc creates _____ strings.
Hint: Multiple lines
7. true and false are _____ values.
Hint: True/False
8. PHP is _____ typed.
Hint: No declaration
Returns -1, 0, or 1 depending on comparison:
1. % returns _____.
Hint: Modulus
2. == checks _____.
Hint: Equal value
3. === checks _____.
Hint: Same type
4. && means _____.
Hint: Both true
5. != means _____.
Hint: Different
6. <=> is the _____ operator.
Hint: PHP 7+
7. .= is _____ concatenation.
Hint: Append
8. ! is the _____ operator.
Hint: Not
The foundation of decision-making in PHP. Use if/else to execute code based on conditions.
Handle multiple conditions with elseif. PHP evaluates conditions top-to-bottom and stops at the first match.
Use switch when comparing one variable against many possible values. Cleaner than long elseif chains for equality checks.
A shorthand for simple if/else statements. Use for simple assignments, not complex logic.
PHP 7+ introduced ?? to handle null values gracefully. Returns the first non-null value.
The modern replacement for switch. Match returns a value and uses strict comparison (===) by default.
1. elseif handles _____ conditions.
Hint: More than one
2. switch compares for _____.
Hint: Same value
3. ?? is the _____ operator.
Hint: Null fallback
4. match was added in PHP _____.
Hint: Version number
Indexed arrays use numeric keys starting from 0. PHP 5.4+ introduced the short array syntax [] which is the preferred modern approach.
Associative arrays use named keys instead of numeric indices, making them perfect for storing structured data like user profiles.
Arrays can contain other arrays, creating nested structures for complex data like tables or matrices.
PHP provides over 80 array functions. Here are the most essential ones for everyday development.
1. Array indices start at _____.
Hint: First position
2. Arrays with named keys are called _____ arrays.
Hint: Key-value pairs
3. _____() returns the number of elements.
Hint: Array size
4. _____ is the preferred loop for arrays.
Hint: For each element
PHP offers multiple ways to define strings, each with different behavior regarding variable interpolation and escaping.
PHP has over 100 string functions. Master these essential ones first.
Regex allows pattern matching for complex string validation and manipulation.
1. _____ quotes interpolate variables in strings.
Hint: " vs '
2. _____() returns string length.
Hint: String length function
3. _____ matches regex patterns.
Hint: PREG function
4. _____() splits a string into an array.
Hint: String to array
Understanding when to use each HTTP method is crucial for secure and functional web applications.
Always validate user input before processing. Never trust data from the client.
Remove potentially harmful characters while preserving valid data.
Cross-Site Request Forgery attacks trick users into performing unwanted actions. Protect your forms with tokens.
1. Use _____ for form submissions that change data.
Hint: Not GET
2. _____() validates and sanitizes input.
Hint: FILTER_VALIDATE
3. _____ tokens prevent cross-site request forgery.
Hint: Cross-site protection
4. _____() compares strings securely against timing attacks.
Hint: Secure comparison
Sessions allow you to store user data across multiple page requests. The session ID is typically stored in a cookie.
Secure your sessions against hijacking and fixation attacks.
Cookies store data on the client's browser. They're sent with every request to your domain.
1. _____() initializes a new session.
Hint: Required first
2. _____ cookies prevent JavaScript access.
Hint: XSS protection
3. session_regenerate_id() prevents session _____.
Hint: Fixation attack
4. Session data is stored on the _____.
Hint: Not client
PDO provides a consistent interface for accessing databases. It supports multiple database backends and is the recommended approach for modern PHP applications.
Prepared statements separate SQL code from data, making SQL injection impossible. This is mandatory for any database interaction with user input.
Transactions ensure multiple operations complete together or not at all - maintaining data integrity.
1. _____ is the recommended database interface in PHP.
Hint: PHP Data Objects
2. _____() creates a prepared statement.
Hint: Prevents SQL injection
3. A _____ ensures multiple operations complete together.
Hint: beginTransaction()
4. Prepared statements prevent _____ attacks.
Hint: Database security threat
PHP offers multiple ways to read file contents, from simple one-liners to resource-based approaches for large files.
Secure file uploads require validation at every step. Never trust the filename or type provided by the client.
1. _____() reads an entire file.
Hint: Simple file read
2. _____() is the safe way to move uploaded files.
Hint: Upload security function
3. _____() converts JSON to PHP arrays.
Hint: JSON parsing
4. _____ validates actual file MIME types securely.
Hint: File info class
Object-Oriented Programming (OOP) allows you to organize code into reusable, self-contained objects with properties and methods.
Control access to class members with public, protected, and private visibility.
Child classes inherit properties and methods from parent classes, promoting code reuse.
Static members belong to the class itself, not to instances. Useful for utility functions and shared state.
PSR-4 is the modern standard for autoloading classes from file paths based on namespaces.
1. A _____ is a blueprint for creating objects.
Hint: OOP blueprint
2. _____ visibility restricts access to the defining class only.
Hint: Most restrictive
3. The _____ keyword creates inheritance.
Hint: Parent-child relationship
4. _____ is the autoloading standard.
Hint: PHP-FIG standard
Cross-Site Scripting (XSS) attacks inject malicious scripts into your pages. Always escape output when displaying user data.
SQL injection is one of the most dangerous vulnerabilities. Prepared statements are the only reliable defense.
Never store passwords in plain text. PHP provides secure hashing functions that handle salt and iteration automatically.
Composer is PHP's standard dependency manager. Never reinvent the wheel - use well-tested libraries.
PHP-FIG PSR standards ensure code interoperability across frameworks and libraries.
1. _____() prevents XSS when outputting user data.
Hint: Escape HTML entities
2. _____() securely hashes passwords.
Hint: bcrypt by default
3. _____ is PHP's dependency manager.
Hint: Package management
4. _____ statements prevent SQL injection.
Hint: PDO prepare()