Introduction to PHP
We live in a world dominated by internet, which is being used by hundreds of millions of people everyday, yet most of these people don’t know much about what it is being ran on. Here I’ll try to explain the basics of the programming languages that generate some of today’s most important websites, in the simplest terms I know, so absolutely anyone can get it. Enjoy
Introduction
Now, there are many different programming languages you can learn, but I am just going to focus on one of the easiest and most convenient called PHP. PHP is a programming language that runs things like Drupal and Wordpress, so it will probably also be the most useful to the average user.
What exactly does PHP do?
This is the big question: What exactly does all this mumbo jumbo do? I will get to that in a second, but first I have to give you a little background about how the world wide web works.
A World of HTML
The website you are looking at is coded in a particular language called HTML. HTML is simply a series of tags inside brackets, like : ‘<body>’, that form all the content in the page. If you wanted to look at the HTML of any page, you can do it simply by going to ‘View’ and clicking ‘View Source’. You’ll see a large document with many things inside brackets. These tags are what all pages are written in, and it’s the basic backbone of internet. You don’t need to know everything about them, just know that HTML controls what the page looks like.
The Internet is a World of Servers.
In one second we’ll get to what PHP does. First, you have to know that whenever you view a page, your browser goes and asks a box for a webpage. This box is called a ’server’, and is located somewhere in the world. It looks very much like your computer, and it’s plugged into the internet the same way your computer is. Whenever a browser wants a page, it looks for the box, finds the one that hosts the website, and asks for the page, which the server then gives back to it in HTML, so it can display it for you.
So, we now know that when your browser asks for a page, the server gives back an HTML page, and the browser displays it to you. It seems like a very simple process, but for websites like Facebook and Google, it gets a little more complicated. If you look at pages like Google and Facebook, you’ll notice that the content on their homepage can change based on when you view it, or settings you have chosen in your ‘Preferences’ page. This is where PHP kicks in.
PHP: The Middleman
PHP basically steps in when a browser asks for the page, and when the server gives the page to the browser. PHP sees that the browser is asking for the page, and then determines what HTML should give back to the browser. Things like, “Is the user logged in?”, or “What time of day is it?”, can be used in PHP to change the page. If it is morning, PHP can make a page that says ‘Good Morning’, and if its evening, it can make it say ‘Good Evening’.
The basic concept of PHP is that it creates the HTML page that the browser gets.
So, let’s look at the whole round trip for getting a page. First, the browser asks for a page from the server. Then the server runs your PHP script, which then tells the server what the HTML should send to the browser. When the browser receives it, the page is displayed.
- Tyler C.