Hi everyone. My name is Jill Gundersen, and welcome to my course, PHP Predefined Variables. I am a software developer, trying to make the world a better place one website at a time. Interaction and usability is a common goal when creating a website. When building a site with PHP, this is no different. PHP provides predefined variables to manage data in order to make websites useful and interactive. In this course, we are going to learn how to handle general data and data from a user input. Some of the major topics that we’ll cover include form processing, website cookies, persistent data, and file uploads. By the end of this course, you’ll have increased your understanding of the PHP programming language, and will have an added knowledge of creating more interactive websites using the PHP predefined variables. Before beginning the course, you should have a working knowledge of the PHP programming language and a solid understanding of associative arrays. I hope you’ll join me on this journey to learn these predefined variables, with the PHP Predefined Variables course, at Pluralsight.
As with any programming language, there is normally a set of reserved or predefined variables available for the programmer to utilize. PHP is no different. In this course, we will uncover the predefined variables that PHP has to offer and demonstrate their use in everyday scenarios. I’m Jill Gundersen, let’s get started.
Accessing Environment Variables with $_ENV
The $_ENV predefined variable is probably the least used out of the eight predefined variables we will be covering in this course. Even though that might be the case, it is important to understand this variable and its contents. The $_ENV predefined variable provides access to all of the set environment variables for the particular server the website is hosted on. The $_ENV predefined variable is one of two predefined variables we are covering in this course that already come prepopulated with data. In the next clip, we will print out the contents of this predefined variable.
Accessing Server Variables with $_SERVER
The $_SERVER predefined variable contains information regarding the script that is executed, the headers that are set, and the paths that are used. In the module, we will discuss some of the more commonly used elements from the $_SERVER predefined variable. This will include accessing the IP address of both the server and the user, plus accessing the browser data that the user accessed your site with. In the next clip, we will print out the contents of this predefined variable.
Accessing URL Variables with $_GET
The rest of the predefined variables that we’ll be discussing in this course are variables that either the user or the developer will load with data while a user visits your website. This means they are initially empty. The first of these predefined variables we’ll be focusing on in this module is the GET predefined variable. In the next clip, we’ll discuss our website setup prior to working with the GET predefined variable.
Accessing Form Data with $_POST
The POST predefined variable is probably the most commonly used of the PHP predefined variables. This variable is used to retrieve user data that has been submitted via a form. In the next clip, we will access submitted form data using the POST predefined variable.
Setting and Retrieving Cookie Data
There are occasions when we want to save a small piece of data on the user’s browser. This is known as a browser cookie or just simply cookie. PHP has a specific function for setting this type of data in the user’s browser. In this module, we will learn how to set a cookie and then use the COOKIE predefined variable to retrieve the data. In the next clip, we’ll learn about the setcookie function.
Accessing Form, URL, and Cookie Data with $_REQUEST
REQUEST is our next predefined variable. REQUEST is a special predefined variable in the sense that it contains the contents of other predefined variables. It contains the contents of the COOKIE, POST, and GET predefined variables. In the next clip, we will demonstrate this using the current web form.
Persistent Data with $_SESSION
After form processing with the POST predefined variable, I believe that the SESSIONS predefined variable is the next most commonly used predefined variable. Sessions and the SESSIONS predefined variable allows for data to be saved and then accessed on any page throughout your website. This persistent data is valuable for sites that require personalization or for sites utilizing a login. In this module, we’ll cover what is needed to get sessions working in your PHP website. In the next clip, we will go over some updates and edits to our HTML in preparation for using sessions in our website.
Uploading Files in PHP
The FILES predefined variable is probably the most looked up predefined variable. As developers, we don’t use it often, but when we do we need a refresher. In this module, we’ll learn the intricacies of uploading a file to our web server using the HTML form and the FILES predefined variable. After we have mastered that, we’ll traverse the crazy associative array created in the FILES predefined variable from uploading multiple files at once. In the next clip, we’ll quickly cover the changes that were made to our website to focus solely on uploading files.