What is PHP & How does it work? What is the purpose of PHP?


PHP is a very popular open-source language, suitable for web development and can be embedded in HTML. It is popular because a large number of web pages and portals are built with PHP. Open source means that it is free to use and free for all programmers who want to use it. Embedded in HTML means that in the same file, we will combine PHP code with HTML code, following some rules.

PHP is used to generate dynamic web pages. Remember that we call a static page the one whose contents always remain the same, while we call dynamic pages those whose content is not the same always. For example, the contents may change based on changes in a database, searches or user contributions, etc.

How does PHP work? The PHP language is processed on servers, which are powerful computers with special software and hardware. When I type an address like http://www.aprenderaprogramar.com/index.php in a web browser such as Internet Explorer, Firefox, or Chrome, what happens? The requested data is sent to the server that processes it, collects the data (that's why we say it is a dynamic process) and the server returns an HTML page as if it were static.

The scheme is Web page request to the server -> The server receives the request, gathers the necessary information by consulting databases or other web pages, other servers, etc -> The server responds by sending a "normal" web page (static) but whose creation has been dynamic (making processes so that the returned web page is not always the same).

In summary:

  • Static Content: Request -> Response
  • Dynamic Pages: Request -> Processing and Preparation -> Response

On a dynamic site, the information is generally contained in a database. Every time we display the page, such as a news page, we search the database for the latest news that we have entered to display in the visitor's browser. Now, how do you get the page to show new news? Simply loading them in the database, for example, through a form that a person fills in and that once filled out when they press "Send" implies that what they have written is saved in our database. In this way, when we request the web page and the server consults the database, it will find this new information and display our page differently from previously seen.

As a general rule, this type of language is usually used to create dynamic content and to interact with the user.

Let's look at an example of the content of a PHP web page, which we will have to store in a file that ends with the extension .php and contains the text:

code


As you can check the content of the file, it includes HTML code and at one point a <? Php tag appears which means that the PHP code begins there. That is why we say that the PHP code is embedded (included or embedded) in HTML code.

Therefore, PHP pages contain HTML with PHP code included in them to do "something" (in this case, display Welcome to aprenderaprogramar.com. PHP code is enclosed in special beginning and end tags: <? Php and?>

These special tags will allow us to enter and exit "PHP mode". They serve the webserver to know that it has to interpret the code included between these tags as PHP.

What distinguishes PHP from JavaScript is that the code is executed on the server, generating HTML and sending it to the client as if it were a static web page. The client will receive the results that the server returns after interpreting the PHP code, without any possibility of determining what code has produced the received result. That is, through our browser, we could see the HTML code, but never the PHP code that produced the HTML result. The web server can even be configured so that users cannot tell whether or not you are using PHP.

The best thing about using PHP is that it is extremely simple for the beginner, but at the same time, it offers many advanced features for professional and more advanced programmers.

With PHP you can process information from forms, generate pages with dynamic content, or send and receive cookies, among many more things. PHP is used by small web pages to large companies. Many web applications are built using PHP. We can mention Joomla and Drupal (web page content managers), osCommerce and Prestashop (online stores for electronic commerce), phpBB and SMF (forum systems for web pages), Moodle (educational platform for online education), etc.

PHP can also use and present results in other data standards or languages ​​typical of web development, such as XHTML and any other type of XML files. PHP can auto-generate these files and store them in the file system instead of displaying them on the screen, using these files to generate dynamic content. That is, dynamic content can emerge from other sites than from databases.

You can also interact with other servers using any protocol. Lastly, PHP can link with other very powerful languages ​​like Java.

In summary, PHP is a powerful language, widely used and of great interest for web development.


Post a Comment

0 Comments