To understand how PHP works, first you have to know how a web page is loaded on your computer screen when you want to visit a website.
When you (client or user) enter a web page URL (universal resource locator, or web address) in your computer browser address bar and you hit the enter button, your computer automatically sends a request to the computer (server) that hosts the web page content. The server requests the PHP script to start performing and processing. The PHP script starts working, creates HTML codes, and then the server sends the HTML codes to your computer and you will see the web page. That is why you don’t see the web pages on your computer screen as soon as you hit the enter button, and there is always some delays. Because your computer has to send the request to the server, the PHP has to process data and generates HTML, and the server has to send the HTML to your computer. These stages need time to be completed:
This is how a PHP-generated site works. It is different from the HTML-generated sites. In HTML-generated sites that are coded in basic HTML originally, and there is no PHP in them, the server sends you the HTML data as soon as it receives your computer request. As there is no PHP in these kinds of sites, the server doesn’t refer to any PHP code to make it process the data and create HTML.
These explanations may look confusing to you if you really have no information and experience about HTML and web developing through HTML. If you like to learn PHP, you need to know the HTML basics (which is very easy and can be learned within a few hours), and the way that a web page can be created and uploaded to a website. You should know what a file like index.html or index.htm mean. Accordingly, when you start learning PHP, you can easily understand that the PHP files have to have .php extension; e.g. index.php
This is the basic information you have to have. If you are just an ordinary internet user, it will be hard for you to understand what I explained above about sending the URL request to the server, PHP processing in the server, and… .
Now the question is, if the server has to make the PHP process the data and create HTML codes, then why don’t we use an HTML website that doesn’t need any PHP processing? What is the point to use PHP?
When you just want to have an static website or web page that just displays some texts and pictures, you can simply use HTML to create it, and you don’t have to use PHP. However, what you need from a website or a webpage is usually much more than displaying some texts and pictures. For example you need the visitors to post comments and ask their questions; you need the web page to react to the actions that the visitors do; you need your website visitors to sign up for an account; you need to have members area that your website users can have access to after they sign in; you need… and so many other things. These things can not be done by a basic HTML web page. You need a data processor that receives the data, stores them in the database, modifies the database data, reads, uses and displays them when it is the time to. PHP is the programming language that can do all of these. Please read this article: Why Use PHP for Web Developing?
Ok! This article was the 3rd PHP training article I wrote. If you like to follow me and learn PHP, please always refer to end of this article and look for the list of my PHP training articles: How to Learn PHP Programming