PHP work

How does PHP work? The function of PHP in WordPress

If you dedicate yourself to designing simple static pages and their content will not change very often, you can manage with just HTML. An example can be a business website that shows data about the company, its location, recent jobs, means of contact, etc. All data is almost constant. But how PHP works? Each visitor who enters said website will process the HTML code through their browser and will be able to view all the content.

Now suppose that the company decides to add a blog on the web, something that will benefit the interaction with its customers. Will we solve it with HTML? It is a possible solution, but keep in mind that every time new content is uploaded, you will have to enter to modify the web code to make the updates. Keep reading how to evolve snom.

We need that the updates (for example, new blog posts) are stored in a database, and then the frontend shows them without touching any code. Well, that’s exactly what PHP is for and how it works.

How does PHP work?

Every time a user visits a website written with PHP, the following happens:

  • Upon entering, a request is sent to the server.
  • The server receives the request and looks for the page to deliver.
  • If the page contains PHP, it is processed.
  • The server executes the PHP code of the page and prepares the final result, the HTML.
  • The HTML page is sent to the user.

Graphically, the operation of PHP can be summarized as follows.

Suppose we have a website with the following code. I have placed the HTML in blue and in green what would be the PHP, (I clarify that the PHP is not written like that, it is only to simplify the example)

<! DOCTYPE html>

<html>

<head>

<title> Example </title>

</head>

<body>

Right now, there is <? Php

How many users are browsing the server?

?>  browsing the web.

</body>

</html>

As explained above, when a user enters, a request will be made to the server. Upon finding the line of PHP code, it will be processed.

The server will ask how many users are browsing. Suppose the result to that question is 25 users. Then that will be the answer that will be sent. As a fine result, the next processed HTML is returned.

<! DOCTYPE html>

<html>

<head>

<title> Example </title>

</head>

<body>

There are currently 25 users browsing the web.

</body>

</html>

Once the browser interprets the HTML code, the final result will only be the text:

There are currently 25 users browsing the web.

In the example, the server’s request was the number of users online, but this could have been to show the last blog entry or comment, the number of times content shared on the networks, etc.

The function of PHP in WordPress

WordPress is a content manager that uses several programming languages. As you may be imagining, PHP is one of them. To say “one of them” is an understatement. PHP is the lifeblood of WordPress, fueling most of the web.

If you explore the compendium of folders that make up any WordPress theme, you will find folders of the type; sidebar.php, header.php, comments.php, and the most popular of all funtion.php. The first controls how the sidebar, header, and comments look and work, respectively. While the folder funtion.php accumulates functions that our theme will use of the various utility.

The moment someone visits your website, the web server will take all those separate PHP files for different areas of the topic, put them together, and deliver the completed HTML output to the visitor’s browser. Yes, yes, all that happens every time you visit a WordPress website.

As a user of the most popular CMS, you can do without knowing about this programming language. But the wide utility that PHP has in WordPress makes it worth it, at least, to know the least.

Well, with this, I finish the post. I hope you have understood what PHP is, its usefulness, and how it works.

Keep reading Does PHP have a future as a programming language?

Tags:
No Comments

Post A Comment