PHP code by the PHP interpreter can only run on the server on the Web side, here we can simply parse the PHP program running flow, the need for friends to refer to the next
Always wanted to understand the technology of web programming. PHP is an important language for Web programming, and the book always says that PHP is a programming language for the server side. However, it is impossible to understand how it is used for server-side programming and how it is run. Also read a few PHP tutorials, mostly the introduction of grammar, but did not give the answers to the previous questions. Recently patchwork to see something, and finally have some understanding of how PHP works.
HTTP protocol and PHP script triggering
HTTP is a request/response-based protocol that is the foundation of a protocol that supports web operations. The HTTP client sends the request
To the server side, the server side returns response. The request contains the file name of the page that the client needs to access. The server side returns the page that the file name points to. If you do not use PHP, JavaScript, and so on, the HTTP protocol transfer can only be static HTML files. That is, the HTML file is not affected by user behavior, and the content remains the same.
If you want to implement dynamic Web pages, you need to use PHP or JavaScript. PHP is a programming language for the server side, and JavaScript is a programming language for clients.
The PHP code is executed on the server side. When a user accesses a Web page that contains PHP code, it sends a request to the server, which contains the file name of the Web page. After the server receives the request, finds the file that the filename points to, discovers that it is embedded with PHP code, invokes the PHP interpreter to process the file, and then organizes the processed results into response, which is sent to the client. PHP code can interact with the server-side database or other resources, or produce different pages depending on the user's actions.
Therefore, the trigger of the PHP script is to receive the request from the client on the server. After receiving a request, the server triggers a PHP script; After the script is processed, the result is returned to the client, waiting for the next request. When the next request is received, the server triggers another (or the same) PHP script. Two times the PHP script runs independently of each other, and the second script runs almost unaffected by the previous script run.
JavaScript code is typically executed at the client, which is handled by the browser. The client obtains the JavaScript code from the server side, not the result of the code being executed, and then invokes the interpreter to execute the code.
Code blocks for PHP
PHP code can be embedded in HTML files, often in the HTML file can see scattered throughout the PHP code block. I've been confused. In the same HMTL file, what is the relationship between different blocks of PHP code. Originally PHP will ignore two PHP code blocks between the HTML code.
The code has two blocks of PHP code that are separated by HTML code. The 1th PHP code block declares 1 variable $var, and the 2nd code block refers to $var, which changes its value. Using PHP to execute the above code, the resulting output is as follows.
The 2nd block of code can refer to $var. Although separated by the HTML code, the execution of the two pieces of code completely ignores the HTML part. PHP output is the same as the following PHP code is not separated by HTML, the former just inserted in the PHP output of the corresponding HTML code.
<?php $var = 1; echo "<p>this is PHP code block 1. <br/> \ $var = $var </p> "; $var + = 1; echo "<p>this is PHP code block 2. <br/> \ $var = $var </p> " ?>