PHP contains many features, but they might not all be enabled on your server, so it's important to check the configuration. In this lesson, you'll learn how to use the phpinfo() function and check the most important settings for your testing environment.
This lesson demonstrates how to change PHP configuration settings by editing php.ini. The video shows important changes that need to be made to the MAMP defaults, but the information is also relevant to Windows users.
Comments not only make maintenance easier by reminding you what the code does, they're also useful for temporarily disabling sections of code. This video explains how comments work, and also how PHP treats white space.
Choosing whether to enclose strings (text) in single or double quotes can make a big difference. In this video, you'll learn how they differ, as well as how to prevent problems with quotes and apostrophes that occur within a string.
Strings can be joined using the concatenation operator, double-quoted strings, or the combined concatenation operator. This last technique is particularly useful for sending email through PHP, as you'll see in this video.
In addition to standard arithmetic operators, PHP has increment and decrement operators that behave differently. You'll learn all about them in this lesson, including the modulo operator and combined assignment operators that perform a calculation on a variable and reassign the result to the same variable.
As this video demonstrates, it's often convenient to store multiple values in a single variable using an array. Indexed arrays automatically assign numbers to array elements, while associative arrays store key/value pairs.
This section dives deeper into the structure of PHP, explaining how to perform different actions based on conditions and comparisons, as well as how to use loops for repetitive actions and accessing the contents of an array.
Using Control Structures and Loops
PHP treats certain values as being implicitly true or false. Understanding this concept is vital to working with conditional statements, as this video will explain.
Switch statements and the ternary operator offer alternative ways of controlling decision-making in PHP. The ternary operator is commonly used as shorthand for simple conditional statements, as you'll see in this lesson.
In this lesson you'll learn how the foreach loop offers a convenient way of accessing every element of an array. It takes two forms: One handles just the element values, while the other gives access to both the key and value of each element of an associative array.
This chapter looks at using PHP's built-in functions and objects with the help of the PHP online manual. You'll also learn how to create your own custom functions and how to decipher PHP's often cryptic error messages.
Functions, Objects, and Errors
PHP has a huge number of built-in functions. This lesson explains the importance of capturing the return value of most functions, as well as how to use a function as an argument to another function and how to use optional arguments.
The PHP online manual contains a wealth of information about built-in functions, complete with examples. This lesson explains how to find your way around the Function Reference and understand the conventions it uses.
Server-side includes allow you to merge files on the server, providing access to external code libraries and simplifying the process of updating common page elements. This video explains why PHP has four separate include commands and suggests which ones you should use.
Normally variables are passed to functions by value, leaving the original value unchanged. However, you can also pass variables to a function by reference, which results in the original value being permanently changed throughout the script.
This chapter steps you through the process of building a reusable script to validate and email user input from an online form. Each video builds on the previous one, so it's recommended that you watch them in sequence. Complete start and end files are provided for each lesson.
Emailing the Contents of an Online Form
Forms can be submitted using the GET or POST methods. This lesson describes the difference between them and explains how to access form data using the superglobal $_GET and $_POST arrays.
Magic quotes insert unwanted backslashes in data submitted through a form. This feature has been deprecated, but is still implemented on many servers. This video explains how to deal with the problem if it affects your server.
The processing script uses arrays to store details of errors and required fields that have been left blank. Checking if those arrays are empty controls the display of error messages alongside each form field, as you'll see in this video.
A loop is used to check the value of each form field, and if a required field is empty, its name is added to the $missing array. The loop also creates new variables based on the name of each form field using a technique known as variable variables, which is covered in this lesson.
In this lesson you'll see how a mail processing script is strengthened by creating a function to detect suspect phrases used in an email header injection attack. If a suspect phrase is detected, the script stops processing the form input.
In this video you'll learn how to add additional headers to the mail processing script and incorporate the user's email into a Reply-to header without exposing the form to an email header injection attack.