Server scripts. Introduction
This "experience" I want to begin new big section. In due time before any web designer there are questions of such type: " how to save the information on the server ", " how to send results of filling of the form on emehjl ".
At once I shall say what to make it it is impossible only means of a browser. For realization of similar things there is a set of special languages. The biggest popularity use perl and PHP. In what their similarity and distinction?
Often confuse concept CGI and perl. CGI (Common Gateway Interface) - the report of data exchange to programs. And perl - special language of a high level on which are realized necessary fukcii interactions with operational system on the server. Generally with help CGI it is possible to start any application on the server and everything, that from him (application) it will be deduced{removed} on a standard stream of a conclusion, will get in a browser. In parallel the application can make a conclusion of the data for a file on the server, send on emehjl or place (to take) something in a database.
Radical difference PHP from CGI consists that PHP is preprocessor HTML. I.e. his job is constructed under the following circuit:
.phtml (.php3)-> php.exe-> a browser
I.e. before the server "will give" a file to a browser, it{he} is looked through with the preprocessor - interpreter. What does it mean? Files which are exposed to processing by a preprocessor, should have the certain expansion (usually .phtml or .php3, but these values it it is possible to change it) and to contain (though it not the obligatory requirement) a code for a preprocessor. This code can be made out by the next ways:
<? php instructions?>
Or:
<SCRIPT LANGUAGE = "PHP">
Instructions
<SCRIPT>
Further I shall more in detail stop on functions of language PHP as I think his more understandable (syntax of it is close to language C ++) and convenient (this my personal opinion so you are free to choose that is pleasant to you more). Besides if it is necessary for us to insert in usual HTML page result of job of simple function it more conveniently to make with PHP as the code can contain directly in HTML a code of page. For CGI, in such situation, we should or deduce{remove} all page from a script, or to use technology Server Side Include.
First I want you to warn, that for functioning PHP the preprocessor should be established on the server. Now it is considered a good form to offer this service on all servers of free-of-charge access. I any more do not speak about the firms giving services of a commercial hosting. Just in case, consult with the system administrator of the server.
And so we can make with help PHP? The most elementary example:
<html>
<head>
<title> the Test </title>
</head>
<body>
<? php echo " Hello, World! ";?>
</body>
</html>
The initial text of the document in a browser looks so:
<html>
<head>
<title> the Test </title>
</head>
<body>
Hello, World! </body>
</html>
With the help of function echo we can deduce{remove} everything, everything in the initial text of the document. Now we shall consider, something more useful.
As you could notice, pages on the majority of servers contain a constant part: navigating panels, trade marks, buttons and so forth. It is rather difficult to copy these things each time when something you add on the site. Earlier, I had to create each time new "experience" from a pattern which, frequently, borrowed{occupied} more places, than experience. Fortunately, in PHP there is a function of connection of external files. Such functions two (actually, their three, but function "virtual" is used only for the server the Apache, and is replacement of the standard directive <! - virtual...): include () and require (). The basic difference of these functions will be, that the second vkljuchet the text of a file in any case, and the first - only if he still nebyl is switched on. For example we shall place the following text in a file header.inc.php3:
<html>
<head>
<title> the Test </title>
</head>
<body>
And the following in a file footer.inc.php3:
</body>
</html>
And in the basic file we shall place it:
<? php
include ("./header.inc.php3");
echo " Hello, World! ";
include ("./footer.inc.php3");
?>
The given example, certainly, is not indicative. But I can say to you, that files of heading and end which are used on these pages, in total, borrow{occupy} almost 10 kilobyte.
I think, that for today it is enough. Next time we shall consider how to pass in a script variables.
For now see a site of language PHP: http://www.php.net/. There you can find the distribution kit and the full documentation. Distribution kits are available for all conducting{leading} platforms. At me on a computer on which I also write these experiences, it is established PHP versions 3 and Apache server. All works normally and very much udbono to debug pages, not sending them on the removed server. I advise you to establish at myself such sheaf.

|