PHP Basics

phpinfo & Server Variables

Maximiliano Firtman

Maximiliano Firtman

Independent Consultant
PHP Basics

Check out a free preview of the full PHP Basics course

The "phpinfo & Server Variables" Lesson is part of the full, PHP Basics course featured in this preview video. Here's what you'd learn in this lesson:

Maximiliano reviews a few additional superglobal variables. Server variables and the "phpinfo" function are also demonstrated and tips for debugging more complex data types like arrays are also shared.

Preview
Close

Transcript from the "phpinfo & Server Variables" Lesson

[00:00:00]
>> Maximiliano Firtman: So we have cookie. We have session that we will mention sessions later. We have files, this is when you receive files, when you're uploading files, when you have a upload button and you have uploading files, when you receive from PHP, receive files. Now we have $_SERVER. With $_SERVER, you receive a lot of information like the IP address, headers, information, the metadata about the current state.

[00:00:30]
And we'll probably use one of those variables later. I want you to try something. Create a new file. Let's save that as info.php, info, I have a typo there. Open <?php and just call this function phpinfo(), that's all. And run it in the browser just that, phpinfo(), you call the function,
>> Maximiliano Firtman: And open that in the browser.

[00:01:09]
How do you open that in the browser? Well, it's local host, the port that you use, in my case 4000/info.php. Remember, we are pointing directly to the PHP file. So phpinfo is a quick way to see if everything is working in with your PHP configuration. Also here you see all the configuration information.

[00:01:34]
Okay, all the plugins, that you have available. I mean, of course It's a lot of information for us at this point, but when you have a question about the version of PHP that we are running in which folder is currently your PHP being executed with which commands? Well, everything is here.

[00:01:54]
Okay, phpinfo, just in general, is there, okay? It's typically a quick way to when you know my server is not working I don't know it's giving me an error on the library well you run phpinfo. And then you see if something's wrong okay you look into that file okay but I just want to tell you that some of the things that we see here can be retrieved using dollar sign server.

[00:02:26]
Well, just because I'm talking about super global variables, I'm going to maybe spoil something that was about to talk later, but let's do it now. What if I wanna see what's inside $_SERVER. So I wanna see what's inside. So you say what echo doing console loading the JavaScript.

[00:02:50]
Let's see, first let's go back to I'm going to start closing things so it's convert. So the problem is, if I try to do in an echo, because it's an array, it says array to a string conversion online didn't work. And I'm just seeing this array, and it's kind of, yeah, I was expecting to see something better, right?

[00:03:17]
Better than just array. So that's why instead of echo, for debugging purposes only, please, okay, there is a function called var_dump, okay? So actually, I'm trying to see why I'm not seeing it here, but anyway, var_dump. var_dump, if I execute this now, again, I'm not saying it's so clear, but it's a different thing.

[00:03:49]
It's giving me a snapshot of what's inside that variable. It's dumping all the variables content. So it's var_dump and any variable, anything. And then you can see, okay, it's an array of 35 elements. It has 'DOCUMENT_ROOT'. This is the path of my file, the server software, the port.

[00:04:17]
The protocol, so request method, post, the script filename, blah, blah, blah, the host. Here, for example, I have all the headers, the HTTP headers, such as the user agent. That's the name of the browser that is requesting this. So, if you wanna know about the current browser this is the key that you need to use, so the browser user agent is server in this key.

[00:04:52]
So i just wanna show you a way that you you have a quick way to debug in a very dirty way. To actually expose, to dump all the contents of a variable in the HTML itself, so you can see what's in this variable. And then say, I wanted the browser information.

[00:05:10]
So then you have it in that now variable.

Learn Straight from the Experts Who Shape the Modern Web

  • In-depth Courses
  • Industry Leading Experts
  • Learning Paths
  • Live Interactive Workshops
Get Unlimited Access Now