How does PHP 1


The way PHP works is not that difficult: A visitor calls up a PHP script on your server via his browser, e.g .: This request is sent over the Internet to your server on which the script is located (if there is no script there, the visitor receives an error message).

The web server will now search for the PHP file on the hard drive, if it has found it, it will be sent to the PHP interpreter to hand over. The PHP interpreter processes your PHP script and transfers the result to the visitor. The result is usually HTML, but it can also be CSS, Javascript, and even images
(yes, PHP can also generate images :)).

When do I use PHP?

PHP can create many formats (CSS, Javascript, images), but mostly it is used for the output of HTML. Now the question arises, "Why should I use PHP at all when I can generate my HTML file directly?". That's easy to answer, an HTML file is static, that is, if you write a table with 10 entries in HTML, only these 10 can be displayed. PHP is dynamic and can create a table with one row or a thousand rows, depending on your needs.

Everything that should be somehow dynamic on your site has to be done with PHP, because HTML is only static:

  • A visitor counter (+1 for each visit)
  • A contact form (the form itself is generated purely in HTML, but the processing of the form data is done with PHP)
  • a guest book (we don't want to have to update the HTML file for every new entry, PHP should do that automatically and in real time)
  • Display what date is today
  • etc.

If you are interested in PHP, check out the PHP tutorial.