Home >PHP >Introduction to PHP

How PHP works

In the early days of the internet, all web pages had one thing in common – they were static. A page was sent to the browser exactly as it was written and displayed the same way, which over time turned out not to be enough.

That is why many technologies were created to bring web pages to life. In simple terms, they can be divided into two basic groups: client-side and server-side technologies.

Client-side technologies rely on a simple principle: together with the HTML page, the browser also receives a piece of program code that runs on the computer of the visitor at the right moment. The right moment can be, for example, a click on a button, moving the mouse over a link, opening the browser window and so on. The browser takes care of running the client-side code, which can be seen as its main disadvantage: the browser must know the programming language the code is written in. An example of a technology that runs on the client side is JavaScript.

Server-side technologies are based on a different principle. When the browser asks the server for a web page, the server first builds the page and only then sends it. Servers can therefore (and in most cases they do) build a different page each time, depending on exactly what the browser asks for.

PHP is a technology that runs on the server. A typical PHP script contains both parts of normal HTML code and parts of program code. When the web server receives a request to process such a script, the following steps take place:

• the server takes the parts of HTML code as they are;

• then the server runs the parts of PHP program code;

• finally it combines the result and sends it to the browser.

This mechanism is extremely important because it lets the server carry out one or even several operations and send the result to the browser in the form of an ordinary HTML page.