Okay, so so far we've been only building the command line programs.
So programs that run in a terminal in a command line interface without a graphical user interface.
And we did that to focus on the PHP language.
It's time to change that and use PHP for what it was made for, which is building dynamic websites.
And that means that we are about to build our first dynamic website.
This would be a very small project, but it will teach us a couple of things and you see it on the screen.
Let me describe what we are going to learn first.
So first and foremost you are going to learn how to start the PHP build in server.
So the PHP binary has a built in web server, which means you don't need any external web server to
run PHP websites, at least for development purposes at your own computer.
Then the things that we're going to learn.
We are going to learn about super globals.
Those are special global variables in PHP.
They are predefined.
They don't require you to use the global keyword, and they are available everywhere and you can't override
them.
There is plenty of them, and they contain a lot of information about PHP, about the environment,
about the request and user input.
The next thing I'd like to focus on is actually a concept, not something strictly related to PHP.
And this is to separate the logic of the page, which is this part where we generate data or read data
from the part that is responsible for displaying the HTML.
I think it is a good practice.
It makes this code readable And things are just easier to find here.
So while speaking about this, let's call it Presentation Layer.
We're going to learn about this shortcut PHP way to quickly output the value of an expression or variable.
So this is this equal sign.
Here you don't need to use the echo statement.
And also semicolon is not required here.
And then there is also the alternative syntax for for each loop.
And every control structure in PHP has this alternative syntax.
So you've got the colon instead of curly braces.
And also the ending is end for each not a curly brace.
And about the project itself, it's rather simple.
We're just gonna display the current server time.
So keep in mind that not the time on your computer, it is the PHP server time.
So they might differ.
And then we're gonna to format all the information from the server in a nice table.
So let's get started.
So we start with just the PHP tag.
Let me define a page title variable.
This would be dynamic PHP page.
And I'm going to close the PHP section right now.
So the goal is that on the top we've got the logic of the page.
And on the bottom we just output HTML.
So let me add an HTML tag a head section where I'm going to output this title.
So I'm using this shorthand syntax.
Page title.
And here I don't need the semicolon.
So after refreshing this page we can see the title is already there.
Okay.
Next up let's display the current time.
So maybe that's not the times where we display the current time on the websites, but we are just playing
around.
So here I'm going to call this date function.
It accepts a specific string which is called the date format.
So you can look up the date function in PHP manual because it describes how you can construct a very
specific date.
In this case this will show that day.
Well, this will show the time including minutes and seconds.
So now let's display this value.
For that we need a body section.
So the actual page content.
So I'm just going to say welcome for now.
And let's add a paragraph.
So we're going to say that the current server time this is important.
It is not your time on your machine.
That's the time of PHP Now lets use this shorthand syntax to output stuff and we use the current time.
And that's it.
Let's refresh the page.
Keep in mind you will have to refresh this page every single time.
It's not happening automatically.
Okay, let's zoom in a bit because I'm not sure this is visible.
Now there is a special kind of variables in PHP and this is called super globals.
So super globals are variables that are available globally.
And you don't need to add the global keyword.
They are really available globally and you can't override their value.
They are kind of read only.
That's why they are not called globals, but they are called super globals.
The names of those variables typically start with an underscore.
So you've got cookie.
You've got environment variables, files that are uploaded and others.
For now, let's vardump the server super global.
So as you see, this contains quite some information like HTTP headers.
The the request URI uh server name which is localhost.
Well useful information.
So now we're going to use this server super global and display this information nicely in a table.
So what we want to do here is a kind of information page about PHP okay.
So right below this paragraph let me add a table because we want this information in a table.
Every table needs a header where you have some columns with titles of those columns.
Let's add a row and two columns.
I'd like this text to be in bold.
So we've got the key.
And next up we've got the value after the T head section we've got T body, which as you can guess contains
the actual elements.
Now you're gonna see the alternative control structure syntax, which is not super different, but it
is often used with when PHP is mixed with HTML.
It is more convenient then.
So we're gonna iterate over this server super global and we want both the key and the value.
So this is this alternative syntax.
Instead of using curly braces you're gonna use a colon.
And that's everything.
Now you need to also close this for each loop.
And you do that by typing and for each.
All right.
Now inside let's add a row and two columns that will display the value.
So we basically now need to output the key without semicolons in case of this shorthand syntax.
And as you can guess the value.
I think this should work fine.
So now initially we had this data var dumped.
It's totally unreadable.
Now let me refresh the page.
And this is what we have right now.
The current server time and all the information about the request in a nicely formatted table.