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.
For example, the current web page that you are on, is a dynamic PHP page. As you see, you can leave a comment at the bottom of the page. At the left side, you can share the page in the social bookmarking sites without having to leave this page or reloading it. You can sign up for an account here and then login to your account here. After login, you can submit an article here for our review, or open the saved article here and edit it. You can complete your profile, upload your photo, enter your website, FaceBook, Twitter, Google+ addresses here and… . As the website admin, I can read your submitted articles, edit and publish them on the site. I can leave you a note and ask you to proofread your articles and resubmit them for my review. I can do hundreds of other things… . None of these things were possible to do with a basic HTML site. That is why we have to use PHP.
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: