Static and dynamic web pages. Static and dynamic web pages. Database model development

Direct indexed link to the site- this is a link not blocked by prohibitors HTML tags and/or attributes, as well as without any redirections (redirects). For example, if you decide to place a link to my site on your website/blog, it is advisable not to hide it from search robots with the prohibiting nofollow attribute. If you decide to link to one of my pages, please open the link for indexing. I would be grateful for direct indexed links to my site.
If you use graphic/text content or any fragment/quote borrowed from this site on your website/blog, the link to the website must be without any prohibiting attributes and/or redirects.

What is TFP and FTP, what is the difference?

The abbreviations TFP and FTP have nothing in common with each other. The only thing that unites them is the consonance of pronunciation, which can confuse someone.
TFP - (Time for Print), translated as “time per printout”. This term is used by photographers and fashion models. TFP is a kind of currency used by representatives of the photo industry. TFP, as a rule, is secured by an agreement between the model and the photographer, in order to avoid all sorts of troubles related to copyrights, etc.
When a model agrees to TFP, this means that she is ready to work for free for a certain amount of time, and for the work she will receive her photographs (all or some, with or without processing).
Now about FTP.
FTP (File Transfer Protocol) is a file transfer protocol used by web developers and others. To work with the server through this protocol, use FTP client is a program that works directly with the FTP server.
The FTP protocol is used to transfer network documents, such as HTML, PHP, CSS, JPEG, etc., from the developer's private device to the hosting server. The same protocol is used to download network documents from the server to the developer’s private device.

What is a file extension?

File extension, or rather, a file name extension is a sequence of certain characters added to the name of a file. These characters are intended to identify the type, or as they say, file format. A file name extension is nothing more than a combination of letters and/or numbers that comes after the last dot in a file name, for example, fotograf.gif, where “fotograf” is the file name and “.gif” is its extension. There are a huge number of file extensions, but they all correspond to certain standards and areas of application. But if you want to come up with your own original extension for some file, for example, file_name.fotograf, please, no problem! But Windows OS will not be able to open such a file if there is no corresponding program on your machine that sees this extension. For example, if on Windows OS you want to open a file with the extension .gif, this OS knows about this extension and will open some image. But if you want to open a file with the .fotograf extension, such a file will not open, since Windows OS is not familiar with such an extension. A file with this extension can be opened in an application that supports this extension.

What is a business card website, what are there?

Business card website is a website whose main purpose is to present information to the public about a company or individual. Such a site usually consists of a small number of static or dynamic pages.
Business card website pages should contain basic information about the company/individual, the goods they produce and information about their services. These can be pages with price lists, contact details and, of course, a form feedback. A photographer’s business card website, as a rule, differs from other similar sites in its exquisite design and abundance of photographs. The photographer's website must have his portfolio and contacts. IN Lately More and more often you can find a business card website, some of the pages of which are built on FLASH technology, or entirely on FLASH.
FLASH sites look good, but such sites are currently indexed by search engines very poorly, or not indexed at all.

What is a dynamic web page/website?

Dynamic web page- this is a page on which content or some part of it can be generated (changed) in real time without involving additional body movements. For dynamically linked pages, a so-called engine is used - CMS (content management system).
How it works? For example, the page you see in this moment in a browser window, it does not exist in this form. It is assembled from separate parts (templates), which are assembled by the server into one whole. That is, when a page is requested, the web server processes the request and immediately “on the fly” assembles a web page from separate parts and sends it to us for viewing in the browser. Only the page content changes, but the page template remains unchanged.
Imagine a closet that has several shelves with different things. On one shelf there is text content (database), on the other - graphic files(photos, graphic design elements), on the third - scripts (for example, PHP scripts), on the fourth - CSS styles, and so on... This means that when the server receives a request for this or that content, it knows where everything is, and quickly assembles a page for us from the necessary parts: it takes the necessary text content from the database, the necessary graphic files from the graphics shelf, etc. By changing some part of the template in one place, these changes are applied to all pages of the site.

What is a static web page/website?

Static web page is a web document that is located on the server in the form in which the user sees it in his browser. That is, such a document is not assembled from separate parts (templates), but lies on the server as it is, in assembled form, and is downloaded from the server as one file with connections to it CSS styles and/or scripts.
To change the content of such a document, you first need to edit it on your work computer in some HTML editor, and then re-upload it to the server. To change some part of the design or, for example, add/remove a navigation menu item, this will require modifying (changing) all pages of the site.

Web designer and web programmer, what's the difference?

A web designer and a web programmer work in the same field, but they perform different tasks. A web designer is involved in prototyping page designs, developing a website design template, creating a graphic design layout, cutting it into separate fragments and optimization, selecting fonts and colors. A web designer can do the layout of website pages, but this is not his responsibility; for this purpose there are specially trained people - layout designers.
Who is a web programmer?
A web programmer, or rather, a web developer (server developer) is a person who develops special web applications, writing scripts in different programming languages ​​for certain web page modules.
Conclusion, in order for a website to be both beautiful and functional, both a web designer and a web programmer are needed. And in order for the site to be user-friendly, it needs

Website promotion (promotion) is understood as moving a website to the top of search results for certain keywords in search engines. Google systems, Yandex, etc.
Top search results- this is the first page of the site search engine with the first 10 links to sites. For these 10 positions there is an irreconcilable struggle among sites of the same subject. According to statistics, those sites that are at the top (occupy the first three positions) collect the largest number of visitors. In order to be at this top, some resources pay huge amounts of money. But it’s not enough to get there, you need to stay there, and this leads to constant struggle not only among large SEO companies, but also among private

static pages are an exact copy of files located in the directories of the Web server and do not change until the developer himself changes something in them. However, pages can be generated dynamically, that is, while processing a request using some program, and not from a ready-made file on disk. There are several ways to create such a page:

generation on request directly on the Web server. To implement the possibility of dynamically generating Web pages, it is necessary to instruct the server which files are “regular” and which contain instructions for their program processing. Thus, all files in the corresponding directory of a Web site that have “execute” in the list of access rights are considered dynamic, and the server itself selects a means to generate a specific page when accessing such a file based on its attribute and/or its name extension. In this case, the page can be generated either by the server itself (using special commands), or by an external program launched directly or through a CGI interface (common gateway interface). The program for generating a dynamic page can be written in a compiled or interpreted language. The program text containing commands for dynamically generating pages is called a script. The list of correspondence between script attributes and external programs for processing them is specified in the Web server/Script processors section. For example, by default scripts with *.pl and *.cgi extensions are processed by the Perl interpreter;

formation on the user's computer. In this case, the texts of programs for generating dynamic Web pages are first transmitted to local computer user, where the browser must call the appropriate tool for them to process and receive the Web page. The program for generating a dynamic page can also be written in either a compiled or interpreted language.

    1. cgi technology

You've probably come across pages that didn't exist before and that were created dynamically at your request—generated, as they say, “on the fly.”

For example, any review book provides you with a specific form in which you add your review, and then the next time you open that page, it will contain a new message.

One technology that allows you to add dynamic content to Web pages is called CGI. It allows you to associate with a particular URL not just a static document, but a program, as a result of which data can be generated in real time.

Let's look at an example of providing weather information. The weather report changes every day and a new static forecast page may be created daily. However, if you want to provide instant data, you must generate a new page each time. This can be implemented using CGI technology. At the moment of contacting the server, a CGI program is launched on it, which accesses the digital measuring device and provides information about temperature, pressure, etc. The next time you contact this address, you will receive new information.

Another example: when you fill out a request, for example a request in a search engine, in response you receive the results of a CGI program in the form of a set of searched addresses.

A CGI program can be thought of as part of a Web server that is executed by the Web server in real time. The server passes the user's requests to a CGI program, which processes them and returns the results of its work to the user's screen (Fig. 3). On most Web servers, the CGI mechanism is organized as follows: a special subdirectory is created in which such programs are stored, and the Web server administrator configures access to it in such a way that files from it are not read, but are launched for execution. The result of the program is sent to the browser in response to the request. From the client's point of view, it makes no difference whether a given URL is a static document or a CGI program. The browser perceives information the same way, regardless of whether it is generated on the fly or is a static page. The output of a CGI program has the same format as a static document.

You probably came across the abbreviation CGI in your browser while traveling around World Wide Web, and you most likely saw a link to /cgi-bin/ - the directory in which cgi programs are usually located. Many interactive services, such as a guest book, forum, etc., are built specifically on CGI programs.

The term “CGI” refers not only to the program, but also to the protocol. In this sense, CGI is a standard way for a Web server to pass a user request to an application program and receive data back to pass it on to the user. The CGI protocol for sending data between a server and an application is part of the HTTP protocol.

It should be noted that if you are going to host your page on free hosting servers, then it is quite possible that CGI scripts are not supported on these servers.

An alternative to CGI is Microsoft's Active Server Page (ASP) technology, which is built on the same principle: a script included in a Web page is executed on the server before the page is sent to the user.

There are other technologies that work on the same principle.

As can be seen in Fig. 3, The CGI program runs on the server side.

Fig.3.

However, it is also possible to organize dynamic pages by transferring programs to the client computer that generate dynamic page content on the client side (Fig. 4).

Rice. 4

This technology is implemented as follows: active documents are stored on Web servers and downloaded to the local computer in the same way as static pages, but after the active document program is on the local computer, it runs and performs certain calculations on the user's computer, based on for local computing resources. And the results of these calculations are already displayed on the screen. Accordingly, the speed of displaying data on the screen does not depend on the speed of communication with the remote server, since the output of the active document occurs only after it has been downloaded to the local computer. Various technologies can be used to create active documents: applications written in JavaScript, Java applets, and ActiveX controls.

Working day after day to update the content of your Web site, saturating it interesting materials, you're probably thinking that hundreds of new Web sites are created every day, and hundreds of new documents are added every day. How are all these new page arrays created and how are they updated so quickly? All this is not as difficult as it seems at first glance, since it uses the concept of dynamic Web pages.

In this article we will look at the steps of creating a mechanism for publishing press releases on a Web site. Our site will connect on the fly press releases stored in the database with template Web pages. Our goal was not to introduce readers to the basics of Web site development tools, since many books and articles have been written about this. This article is intended mainly for those users who already have experience creating Web pages and simple sites. Our main goal is to show you how to get started developing your first dynamic Web site. To understand the article, it is advisable to have basic knowledge about information systems architectures, hypertext markup language (HTML) and the Perl programming language. To create this site we will use three powerful open source technologies: Apache, MySQL and Perl/DBI.

What is a static website?

Before you dive into developing a dynamic Web site, it's important to understand what a static Web site is and the static Web pages that make up its core. Static Web pages are created manually, then saved and uploaded to the site. Whenever the content of such a page needs to be changed, the user modifies it on his work computer, usually using an HTML editor, saves it and then re-uploads it to the Web site. Taking a close look at some portal, say CNN.com or BBC.co.uk, you might think that these companies attract an army of layout designers to update the content of their sites. In fact there is The best way- use of the concept of a dynamic Web site.

What is a dynamic website?

Each rendered page of dynamic Web sites is based on a template page into which constantly changing content is inserted, which is typically stored in a database. When a user requests a page, the relevant information is retrieved from the database, inserted into a template to form a new Web page, and sent by the Web server to the user's browser, which displays it properly. In addition to information content, navigation elements for a Web site can also be created dynamically. This way, if you need to update the content of your site, you simply add text for the new page, which is then inserted into the database using a specific mechanism. The result is that the Web site seems to update itself.

Creating a dynamic site

The first thing you need to create a dynamic site is a Web server, such as Apache.

A Web server can be used to serve an electronic store, a news server, a search engine, a system distance learning and even for the entire set of listed areas. The choice of a Web server depends on what type of activity an individual or organization intends to engage in on the Internet.

Few strategic business decisions are as significant as choosing a Web server platform. Server characteristics are an extremely important factor that determines the reliability of the node, its “responsiveness” to customer requests, as well as what efforts must be made to maintain it in working order. At making the right choice components and a quality project, a Web site can become a new, more convenient way for customers and partners to interact with your company. Overloading the Web server can cause the database server or some other resource to become unavailable to clients.

Large companies until recently relied on Microsoft Internet Information Server, Netscape FastTrack, IBM WebSphere, and Apache was mainly used by small companies. However, now the situation has changed somewhat, and Apache is beginning to support the performance of some large Internet projects, in particular Yahoo.

You can find the full version of the article on our CD-ROM.

Apache provides rich features that allow you to customize your Web server to suit the needs of individual and corporate users. Settings are made using the directives contained in configuration files. Apache allows you to create virtual Web sites and also acts as a proxy server. If you need to provide access to server content only limited circle individuals, the Web server can be configured so that when accessing specified directories, the server checks login names and passwords in its own database or in one of the databases connected to it.

Next, you need to decide how you are going to store the content that is displayed on the Web page. In this article, using a specific example, we will show how to create a database in MySQL DBMS, which will allow us to break Web content into tables containing fields and data records. A field is a discrete unit of data in a table. For example, we can create a table tbl_news_items with the fields col_title, col_date, col_fullstory, col_author. MySQL DBMS is an excellent choice for creating such a database due to its ease of use and administration, free distribution for various platforms, including Linux and Windows, and its rapidly growing popularity.

After this, we will create dynamic HTML template pages. To develop applications to interact with the database and templates, we will use the Perl language.

In fact, we need to create three Perl programs, or scripts: one will display links to all available press releases (pr-list-dbi.pl), the other will display the contents of the selected press release (pr-content-dbi.pl) , and the third will allow us to add the latest press release to the database (pr-add-dbi.pl). The layout work can be entrusted to your favorite HTML editor, for example, Allaire HomeSite (http://www.allaire.com/). Just remember that when creating a template, you must leave empty areas into which dynamic content will be inserted (of variable length, of course).

Once you've developed the overall design for your press releases, simply insert your specific keywords into the blank spaces above (see below for more on this). Once a user requests a press release, the Web server will process the Perl code and replace the keywords in the templates with content pulled from the database, that is, a specific press release.

The last thing to do is to upload your templates to the Web server in specific directories. You can use the FTP client CuteFTP (http://www.cuteftp.com/), but we prefer to use the FAR file shell. Two important things to remember: first, template files must contain names ending in .pl, and second, they must have execute permission (on UNIX systems, you must execute chmod command 0755 template_name.pl). This is all!

Adding functionality

It is not particularly difficult to add functionality to the mechanism for publishing press releases. You can sort links to press releases available in the database by date or title, grouping them by year. Or, for example, you might want to display a random press release on your Web page, providing information from time to time to visitors regardless of when it was actually published. But perhaps the most important and useful functionality will be adding an HTML form to enter the content of the press release and developing a CGI program in Perl to process this form and then place the document in the database. Recall that CGI (Common Gateway Interface) is a protocol, mechanism, or formal agreement between a Web server and a separate program. The server encodes input data, such as HTML forms, and the CGI program decodes it and generates a stream of output data. The protocol specification does not say anything about any specific programming language. Therefore, programs that comply with this protocol can be written in almost any language - C, C++, Visual Basic, Delphi, Tcl, Python or, as in our case, Perl.

Let's summarize some results. We hope that this article will help you appreciate the advantages of the concept of dynamic Web pages over static ones. Applying this concept will reduce manual work, help distribute the server workload, and allow you to quickly increase the amount of content on the site. The combination of Apache, MySQL and Perl will provide a virtually free, easy to use, flexible to install and configure cross-platform and scalable development environment. Here we will not consider the specifics of their installation, since, firstly, there is simply not enough space allocated for this article, and secondly, each of these tools comes with very detailed documentation.

Creating a database in MySQL DBMS

Database model development

The first and most important step in creating a database is developing its model. So let's get started.

Step 1

We need to name the database somehow. Let's call it db_website.

Step 2

It is necessary to determine what exactly the database tables will contain. A database can contain hundreds of tables. At first we will need just one table to store our press releases. Let's call it tbl_news_items.

Step 3

We need to define the fields that our table will contain. These fields will represent all the elements of the press release. Our example uses five fields: col_id (numeric identifier of the press release), col_title (title), col_date (publication date), col_fullstory (content), col_author (author name). The col_id field will contain a unique identifier by which the user can query the content of a specific press release.

Database creation

Now we need to establish a connection to the MySQL DBMS and create our database. Below we'll show you how to do this from the command line. However, there are many management systems, or MySQL DBMS managers, that allow you to administer it using a user-friendly graphical interface.

First of all, you should definitely know the basics of the language SQL queries(Structured Query Language). The MySQL DBMS package includes a complete description of the supported SQL specification. This language is easy to understand because its operators and their constructs are easy to understand and remember. To work, you will need operators for creating (CREATE or INSERT), selecting (SELECT) and deleting (DROP or DELETE) data, as well as changing them (UPDATE, MODIFY). In specific examples we will use only some of them.

To avoid setting up user accounts and assigning the necessary access rights, let's assume that you are using the administrator account (root).

Step 1

Open a terminal window (if you are working in the X Window graphical shell of Linux OS or Windows 9x/NT/2000) and establish a connection to the MySQL DBMS by entering command line mysql. You should be prompted to enter mysql> commands in response.

Step 2

Let's create our database by entering:

CREATE DATABASE db_website;

After entering each command, do not forget to type the symbol (;). This is very important because it signals the end of command input to MySQL.

Use db_website;

Step 4

Let's create a table tbl_news_items, where we define the type of data that will be stored in its fields. Enter:

1. CREATE TABLE tbl_news_items (2. col_id INT NOT NULL AUTO_INCREMENT PRIMARY KEY, 3. col_title VARCHAR(100), 4. col_author VARCHAR(100), 5. col_body TEXT, 6. col_date DATE 7.);

Step 5

Now that we have created a table to store our data, we need to fill it with some sample data. Note that in the following command we will not define the col_id field because it is automatically populated as new data is added. Also keep in mind that the syntax for date is<год/месяц/день>. So, at the mysql> command prompt, enter the following command.

8. INSERT INTO tbl_news_items (col_title, _ col_author, col_body, col_date) 9. VALUES (10. 'My first press release', 11. 'Your Name', 12. 'This press release is stored in the MySQL database', 13 . '2001/4/15' 14.);

Enter a few more similar requests to insert. To view what is stored in the database, at the mysql> command prompt, enter:

SELECT * FROM tbl_news_items;

Creating Dynamic Web Pages in Perl

Preparing for work

To run Perl programs, you will need a Perl interpreter version 5.005 or 5.6 of the Perl Standard or ActiveState Perl distributions for UNIX or Win32. If you will be developing applications to run under Win32, then the package from ActiveState is somewhat more convenient to use, and it also includes a PPM utility for installing additional modules.

To organize the interaction of our Perl programs with the MySQL DBMS, it is necessary that the DBI module be included in the Perl distribution. Since the module basically does nothing itself, but shifts all operations on interaction with databases to the corresponding driver, the installation of the DBD-Mysql library (MySQL database driver for the DBI module) is required. As stated by Tim Bunce, the author and developer of the specified module, “DBI is an API for organizing access to databases from Perl programs. The DBI API specification defines a set of functions, variables and rules used to interface transparently with databases."

The concept of database drivers is very convenient because in your Perl application you use standard DBI calls, which then forward the modules to the appropriate driver, which, in turn, will directly interact with the database without requiring you to learn technical features each specific DBMS. So there are DBD::Sybase, DBD::Oracle, DBD::Informix, etc. drivers. (Fig. 1,).

Let's go a little beyond the scope of the article. Let's assume that the DBI package does not include a driver for a specific DBMS. In this case, the DBD-ODBC bridge will come to the rescue. It is enough to create a new data source (Data Source Name) for the ODBC (Open DataBase Connectivity) driver, where you need to select the type of this DBMS, the host address to which you want to establish a connection, the database name and authorization data, that is, the user name and password (Fig. .3). And then, using the DBI module, interact with the database. In addition, ActiveState Perl typically comes standard with a Win32::ODBC module (Win32-ODBC). Working with it is a little different from working with DBI, but overall very similar. The only difference is that Win32::ODBC is a module only for Win32 systems and allows you to work with native ODBC functions more efficiently than DBD::ODBC.

A parallel can be drawn between ODBC and DBI. DBI is an analogue of ODBC Administrator (database driver manager). Each DBD driver corresponds in its functions to an ODBC driver. The only thing that may confuse you is the fact that, as mentioned above, there is a DBD::ODBC driver. But it only allows you to establish DBI communication with ODBC drivers.

To install DBI and DBD-Mysql, using the PPM utility in a Win32 environment, enter at the command line:

Ppm install DBI

Please note that your computer must be connected to the Internet at this point. If you have the corresponding module on your local disk, use background information by entering the command:

ppm help install

For UNIX users, installing the DBI module will be almost the same as installing other Perl modules:

Tar –zxvf DBI-1.06.tar.gz cd DBI-1.06/ perl Makefile.PL make make test make install

You can also use the CPAN shell. If you have the UNIX version of the ActiveState package installed on your computer, you can also work with the PPM installation utility. Sometimes it happens that the CPAN and PPM shells do not function if there is a firewall installed on the enterprise network to which your computer is connected, or firewall(firewall). In this case, only modules with source codes downloaded manually will help you. To install them and connect to Perl or Apache, you will need a Perl interpreter, a C/C++ or GCC/PGCC compiler, and one of the make build utilities (from one of the UNIX clones, as well as Microsoft Visual C++), nmake or dmake. Thus, the installation procedure for modules becomes somewhat more complicated. Almost all of them come with "build" documentation, so you shouldn't have too much trouble.

Displaying a list of articles

Now that you have a working press release database, you can easily connect it to your Web page. Let's start with creating simplest page, which displays a list of all available press releases. Note that by default the Apache Web server "thinks" that all your documents should be in its htdocs directory, and executable files- in cgi-bin. Therefore, you need to place all files with the .pl extension in the cgi-bin directory. In its turn, generated files HTML templates must be placed in the tpl directory. The directory hierarchy will look like this:

/ (root of any disk) /local /local/usr /local/usr/bin /local/usr/cgi-bin /local/usr/htdocs /local/usr/tpl

For DOS/Windows systems, the path to cgi-bin may look like this:

C:\local\usr\cgi-bin

Step 1

Using your favorite text editor, create a file pr-list-tpl.htm:

15. 16. 17. Press releases 2001 18. 19. 20. @BLOCK@ 21. 22.

This file is intended to display a list of all available press releases.

Step 2

Create a file pr-list-block-tpl.htm that will display each block with the found press release in the form of a table:

23.

24. 25. 26.
@TITLE@
@AUTHOR@, _ @DATE@

Step 3

Create a file pr-content-tpl.htm that will display the content of the press release:

27. 28. 29. Press-releases 2001: @TITLE@ 30. 31. 32.

@TITLE@

33. 34. 35. 36. 37.
@TITLE@
Author: @AUTHOR@ Date: @DATE@
@BODY@
38. Show the list of press-releases.. 39. 40.

Step 4

Create a Perl script pr-list-dbi.pl that will read data from the db_website database and, using HTML template files, display a list of press releases (you can find the text of this script on our CD).

Now let's go through the code listing and see how the program for displaying a list of press releases works.

Lines 1-9 are like an initializing block in which all global variables and constants are declared:

41. #!/local/usr/bin/perl 42. 43. use DBI; 44. $dbh = DBI->connect(‘dbi:mysql:db_website’,’root’,’’); 45. $path = "/local/usr/tpl"; 46. ​​$TPL_LIST = "$path/pr-list-tpl.htm"; 47. $TPL_LIST_BLOCK = "$path/pr-list-block-tpl.htm"; 48. 49. print "Content-type:text/html\n\n";

We first tell the Apache Web server the path to where the Perl interpreter is located, which runs when the script is requested, checks it for errors, and then executes it. Next, we declare the DBI (DataBase Interface) module, the methods of which will be used in the program to interact with the database (line 3). We then establish a connection to our db_website(4) database using root (administrator) as the login username and an empty string (the default) as the password. In the $path variable we indicate the path where the HTML template files are located (5). In the variables $TPL_LIST and $TPL_LIST_BLOCK we indicate their names (6, 7) respectively. Then, we tell the Web server that all outgoing data should be presented in the text/html MIME format to output the HTML stream to the user's browser (9).

Lines 11-22 represent the body of the program:

50. 51. open(L, "$TPL_LIST"); 52. while ($line1= ) ( 53. chomp($line1); 54. if ($line1=~/\@BLOCK\@/) ( 55. read_db(); 56. ins_data(); 57. ) else ( 58. print "$line1 \n"; 59. ) 60. ) 61. close(L); 62. 63. $dbh->disconnect;

Open the template file pr-list-tpl.htm (11) and look through it in a loop (12-20), writing each line read to the $line variable. During each iteration, we check for the presence in this line keyword@BLOCK@ (14-19), meaning that in this place you need to insert a block with a press release. As soon as it is found, we call the read_db() and ins_data() procedures.

Lines 26-39 are the body of the read_db() procedure, designed to read the contents of the tbl_news_items table, which stores our press releases:

64. 65. 66. sub read_db ( 67. $c=0; 68. my($sql) = "SELECT * FROM tbl_news_items"; 69. $rs = $dbh->prepare($sql); 70. $rs ->execute; 71. while (my $ref = $rs->fetchrow_hashref()) ( 72. $id[$c] = "$ref->('col_id')"; 73. $title[$c] = "$ref->('col_title')"; 74. $author[$c] = "$ref->('col_author')"; 75. $date[$c] = "$ref->(' col_date')"; 76. $c++; 77. ) 78. $rs->finish(); 79. )

We initialize the counter $c=0, make a request to select all data from the table (28), execute the request (29, 30) and get the data into the recordset (recordset) $rs. Then, in the loop (31-37), we extract data from the recordset using the fetshrow_hashref method and returning a link to the associative array %ref (31), containing the names and values ​​of the fields of the current record. We write the extracted data (32-35) into the usual @id, @title, @author and @date arrays corresponding to their types. We close the record set (38).

Lines 41-53 - the body of the ins_data() procedure, which implements the insertion of data extracted from the database into the outgoing data stream; lines 55-63 - the body of the pr_block() procedure, called in a loop from the ins_data() procedure:

80. 81. sub ins_data ( 82. $toread = "pr-read-dbi.pl"; 83. for ($i=0; $i<$c; $i++) { 84. $line = &pr_block; 85. 86. $line =~ s/\@NUMBER\@/$id[$i]/; 87. $line =~ s/\@TITLE\@/$title[$i]/; 88. $line =~ s/\@AUTHOR\@/$author[$i]/; 89. $line =~ s/\@DATE\@/$date[$i]/; 90. $line =~ s/\@READ\@/$toread/; 91. print "$line"; 92. } 93. } 94. 95. sub pr_block { 96. my($block) = ‘’; 97. open (B, "$TPL_LIST_BLOCK"); 98. while ($line=) ( 99. $block = $block.$line; 100. ) 101. close(B); 102. return ($block); 103.)

So, having received the maximum value of the counter $c as a result of the read_db() procedure, in the loop (43-52) we launch the pr_block() procedure, which reads the contents of the HTML template pr-list-block-tpl.htm and writes it to the variable $block (59), the value of which is then returned (62) to the $line variable (44) of the ins_data() procedure. Further in the same loop we replace (46-50) the keywords @NUMBER@, @TITLE@, @AUTHOR@, @DATE@, @READ@ found in the outgoing stream $line with the array values ​​corresponding to this iteration of the loop ($i) @id, @title, @author, @date and the $toread variable.

Printing the press release text

After we have displayed a list of all press releases available in the database (Fig. 4), we need to give the user the opportunity to view the text of any of them (you can also find the corresponding script on our CD).

The new script pr-read-dbi.pl will differ slightly from the pr-list-dbi.pl we have already created.

This listing is 98% similar to Listing 1, although there are some minor differences:

  • the CGI library is connected to read the id parameter (9) from the query string (for example, http://localhost/cgi-bin/pr-content-dbi.pl?id=1);
  • only one HTML template is used (pr-content-tpl.htm);
  • the database query is supplemented with a conditional SQL WHERE statement to retrieve all data corresponding to a specific press release by col_id;
  • The col_body field with the text of the selected press release is also read from the database.

Creating a new press release

Let's expand the functionality of our system by adding the ability to create new press releases, without the need to directly work with the database to replenish the tbl_news_items table with new information.

So, the new Perl program (which, like the previous two, is on a CD) will differ from the previous ones primarily in that it is intended not for displaying data, but for adding it to the database. Therefore, we must slightly change the part responsible for interacting with the database by using the INSERT SQL query and the corresponding DBI module operators.

Lines 12-18 are the body of the main program:

12. if ($cmd ne "add") ( 13. &show_form; 14. ) else ( 15. $dbh = DBI->connect('dbi:mysql:db_website', _ 'root',''); 16. &add_pr; 17. dbh->disconnect; 18. )

Here we check if the command to add the press release to the database has been received. As soon as it arrives, we establish a connection to the database (15), execute the app_pr() subroutine (16) and terminate the connection (17). If there was no command, then we simply display the filling form (13) for the press release data - the show_form() procedure.

Lines 20-36 are the body of the press release adding procedure pr_add():

19. 20. sub add_pr ( 21. $title = $q->param("pr_title"); 22. $author = $q->param("pr_author"); 23. $body = $q->param( "pr_body"); 24. $body =~ s/\r\n/
/g; 25. 26. my($sql) = "INSERT INTO tbl_news_items (col_title,col_author,col_body,col_date) VALUES (\'$title\',\'$author\',\'$body\',CURDATE()) "; 27. $rs = $dbh->do($sql); 28. 29. if ($@) ( 30. $rc = $dbh->rollback; 31. ) else ( 32. $rc = $dbh->commit; 33. ) 34. 35. print "Location: /cgi -bin/pr-list-dbi.pl\n\n"; 36.)

First, we process the form data (22-25), compose an SQL query (27) and execute it (27) using the DBI method $dbh->do(). Since the procedure for inserting data into the database is performed here, you need to take care of the possibility of canceling the operation in case of failures. To do this, we inserted code to cancel the transaction and rollback to the previous state (30-34). If $dbh->do() fails, we discard the changes made (31). If no failure occurs, then we confirm the changes made (33). Then, after all the steps, we simply go to the page with a list of all press releases (36).

Lines 37-55 are the body of the form output procedure for entering information about a new press release (using the HTML template whose name is specified in the $TPL_INSERT variable, pr-add-tpl.htm):

37. 38. sub show_form ( 39. print "Content-type:text/html\n\n"; 40. 41. open (L, "$TPL_INSERT"); 42. while ($line= ) ( 43. chomp($line); 44. if ($line=~/\@/) ( 45. if ($line=~/\@ADD\@/) ( 46. $toadd = "pr-add -dbi.pl"; 47. $line =~ s/\@ADD\@/$toadd/; 48. ) else ( 49. $tolist = "pr-list-dbi.pl"; 50. $line =~ s/\@LIST\@/$tolist/; 51. ) 52. ) 53. print "$line\n"; 54. ) 55. close(L);

System overload

Since you are developing a dynamic Web site, the amount of information on it can grow very quickly. In addition, as the popularity of your resource grows, so does the number of its visitors, which can lead to server overloads, that is, a decrease in system performance. Before you start looking for ways to increase hardware power and try to find a configuration new system, you can try to eliminate one of possible reasons excessive consumption of RAM. The culprit may be the same Perl. The fact is that every time you access one or another Perl script, the Web server loads the interpreter into RAM(it takes up from 500-1000 KB on the hard drive), and the latter parses the program from beginning to end in search of syntax errors. After that, it reads it again, initializing variables and functions, reading the input data (parameters), processing and returning the results. Can you imagine what happens if hundreds of visitors to your site want to view your press releases at the same time?

To speed up this process, special solutions have been created that represent additional modules for the Apache Web server - mod_fastcgi and mod_perl.

The FastCGI module (mod_fastcgi) involves the widespread use of data exchange tools between running processes (tasks) operating system. At the start of its operation, the Web server activates a CGI program and leaves this program and several copies of it running in background. Any requests to the program will simply be transferred to already active copies, which will relieve the server of the additional load associated with re-activating the process.

The mod_perl module allows you to load Perl into RAM in the same address space as the Apache Web server itself, and leave Perl in memory until the latter terminates, preventing the next copy of the interpreter from being loaded when accessing a CGI program. This module is used more often than FastCGI because it does not require any changes to the program.

ComputerPress 6"2001

There are a huge number of different resources on the Internet. Each project consists for the most part of HTML document pages, which are divided into static and dynamic based on the behavior of the document in the browser. On the other hand, these concepts are often used in another sense. Thus, according to the method of creation, documents are also divided into static and dynamic.

The definition of static sites is that the pages always look the same, regardless of user actions. Static sites, as a rule, are less interesting to the user, since they have virtually no interactive elements, unlike dynamic sites.

Dynamic sites, which include dynamic pages that are generated “on the fly” at the request of the browser. These are pages that can already respond to user actions and change. For example, when you click on the text, a block of text with the translation of the word may pop up. The user can interact with dynamic pages while immediately displaying the result of their actions.

Static site pages

Static site is considered a network resource that includes static pages (html, htm, dhtml, xhtml) that make up a single whole. It contains (in the form of HTML markup) text, images, multimedia content (audio, video) and HTML tags. Tags can be either service tags, intended for the browser, or intended for placement, shaping the appearance and display of information. All changes to a static site are made to the source code of the resource documents (pages), for which you need to have access to the files on the web server.

Pages of static sites are stored on the server as HTML documents. Pages of static sites are designed manually. If you need to change the content of a page, you have to edit the HTML code for each page.

Typically, a static site contains one or a small number of pages, or, for example, if it is a business card site of a company and the information on it never changes or is updated very rarely. On such a network resource there are no opportunities such as, for example, commenting or registration, etc.

Ultimately, a static resource can only be updated by a person well versed in web development, since there is no administrative panel, so all updates to the project will have to be done through its source code.

Static sites are cheaper and take up less hosting space, which is why many small companies still prefer them to dynamic sites.

The advantages of static sites include:

  1. They are simple and quick to develop
  2. Cheap to develop, create minimal load on the web server and load quickly.
  3. Not demanding on hosting resources.
  4. It is quite easy to transfer a static website to a new hosting.

Along with the advantages, static sites also have disadvantages:

  1. Web development experience is required to update the project. To update even the smallest detail on such a resource, you will either have to deal with the HTML and CSS code yourself, or you will need to resort to the services of a webmaster every time.
  1. Stagnation of content. Due to the fact that the content of a static site is updated very rarely, this has a very adverse effect on traffic and project promotion in . Of course, you can promote such a resource, but mainly through paid methods.
  1. Also, a static site is not advisable to use in large projects.

From here it is obvious that if the server has a regular html page, then this approach is very limited. For example, there is an online store to which a new product has been added. If such an online store consists of “static” pages, then you will need to manually edit several other pages. At a minimum, this is a product catalog and, apparently, an order form. And, if a product runs out, then again you have to update the static site, which is very inconvenient. In this regard, it is difficult to find an online store on the Internet that uses “pure” HTML code.

Dynamic site

Dynamic site- a network resource consisting of dynamic pages - templates, content, scripts and other things, in the form separate files. Dynamic pages, ultimately shown to the user’s browser, are formed on the server side upon request, from a template page and separately stored content (information, scripts, etc.). As a rule, to display any number of pages of the same type, one template page is used, into which the corresponding content is loaded, this allows one-time adjustment appearance dynamic site (many of all its pages), editing just one template.

Dynamic pages are generated by a web server from several files (templates). All information is usually stored in a database. Almost all blogs are dynamic sites. When a user requests a page, the relevant information is retrieved from the database, inserted into a template to form a web page, and sent by the web server to the user's browser. Thus, when updating the content of a dynamic resource, you simply need to add text to new page, which then goes into the database. Ultimately, it follows that a dynamic site seems to update itself.


The advantages of dynamic sites are:

  1. The resource is more functional, since content is managed through special forms that make it easy to add, edit and delete information.
  2. When adding or editing content, no special knowledge in the field of web mastering (HTML, CSS) is required.
  3. The ability of a dynamic page to change content in response to visitor actions.
  4. Ability to create large multifunctional projects.
  5. Dynamic pages are much easier to modify and update.
  6. Separating information and design on a dynamic site allows for more flexible management.
  7. Constant updating of a dynamic site provides great opportunities for promotion, which has a positive effect on the promotion of the project and it has more visitors.

Along with the advantages, dynamic sites are not without their disadvantages:

  1. The need to use additional software, which translates into the high cost of creating and maintaining dynamic pages.
  2. Increased hardware requirements server systems. This problem becomes especially noticeable on dynamic sites with high traffic.
  3. Hosting will also accordingly be a little more expensive, since for such a project you will need to connect additional features.
  4. The complexity of large structural changes to dynamic pages. In this case, everything depends on software, which is used by the resource. Any program has its own limitations, to circumvent which you need to change the program, modify the old one, or look for a new one.
  5. You need to have the appropriate knowledge to maintain the functionality of dynamic pages.

Tools for creating dynamic pages

If static sites do not undergo virtually any changes and the page appears on the visitor’s monitor screen in its “original” form, then the dynamic page as a person sees it does not exist on the server. She's going several different ways from data stored on the server, and only after that is shown to the visitor.

The first option may be to combine several (two or more) separate parts into one - this is the simplest method of generation.

The second option is to fill the template page with some information stored separately or obtained as a result of the algorithm (for example, as a result of calculations).

The third, and perhaps the most common option is a combination of the first two in all possible variations, i.e. the page is assembled from several pieces, into which various changes are made.

The most common tool for creating dynamic pages is the JavaScript programming language. VBscript is used much less frequently ( visual basic script).

If a resource contains frequently changing content, then scripts are usually used, which, unlike JavaScript, are executed on the server.

In this case, the dynamic site works like this:

  1. The browser requests a document from the server.
  2. The server determines that the document is a script and runs it for execution.
  3. The script generates an html page.
  4. The server sends the generated page to the browser, so that the browser has no idea that the script has been executed on the server.

There are several programming languages ​​that allow you to write scripts for dynamic pages. The most common of them:

Perl
SSI
PHP
A.S.P.
Python
Java
Binary code (a C or C++ program compiled into executable code).

Each of these programming languages ​​has its own application features. You can write scripts in any language. The main thing is to know its strengths and weak sides and use them effectively.

Dynamic sites not only put forward new requirements for their creation and maintenance, they are also much more expensive to develop, and also require the maintenance of a new staff unit - a programmer. At the same time, it should be noted that technology does not stand still, so the possibilities offered for creating dynamic pages are also evolving. And here a solution was found in the form of creating high-quality resources on CMS, which are now gaining more and more popularity.

CMS is an abbreviation for Content Management System, which literally translates to Resource Content Management System. Simply put, this is the same software package that allows you to change the design and content of dynamic pages in the way the user requires. By the way, SMS are based on one or more of the above mentioned programming languages.

Currently, there are many such systems operating on the Internet, some of them are free, some are paid. Often such systems are provided to their clients by the corresponding development companies. Each system is individual and has its own advantages and disadvantages.

Thus, dynamic sites are much more flexible in management. Dynamic pages are a combination of text and graphics, markup language - just like static sites. However, in addition to this, dynamic pages also use various technologies that allow you to “assemble” web pages on the fly. Such resources help their owners unite a community of visitors around them and provide much more opportunities to communicate with their audience, which allows them to make it more interesting for visitors through various functions.

Dynamic resources can be developed from scratch, manually creating all the necessary program codes, scripts, etc. However, much more often special content management systems are used to create dynamic pages - CMS. CMS allow you to use ready-made software modules and components, without the need to create them from scratch each time. You can create any number of projects based on one CMS.

At the same time, despite the obvious advantages of dynamic pages, you should not assume that dynamic sites are always the right solution and completely abandon the pages of static sites. You should always proceed from the situation. It is not without reason that they say that even with the railway you still need a gig. It is often necessary to use static pages in a project. If the project is small, consisting of only a few pages, and the content on it is not updated, then there is no point in creating an engine for the resource - it’s easier to layout all the necessary pages once. But this is not possible in all cases.

Even beginners are probably familiar with the phrases “static site” and “dynamic site”. But what exactly do these phrases mean and what is the difference between them, what are the advantages of one or another type of site?

Let us not guess, but simply look at them in detail and compare them.

Static and dynamic sites - what's the difference?

Although today the number of dynamic sites is increasing, it is impossible to say for sure whether the site you have opened is static or dynamic at first glance.

Static sites examples

You can assume at first glance that a site is static if, for example, it contains one or a small number of pages, or, for example, if it is a business card site of a company and the information on it never changes or is updated very rarely, if It does not have such features as, for example, commenting or registration, etc.

In fact, a static site can only be updated by a person well versed in web development, since it does not have an admin panel, so all updates to the site will have to be done through its source code.

Static sites are cheaper and take up less hosting space, which is why many small companies still prefer them to dynamic sites.

So we can see advantages of static sites:

  1. They are simple and quick to develop
  2. Cheap to develop and less load on .

Along with the advantages, we can also highlight Disadvantages of static sites:

  1. Web development experience is required to update the site.
  2. To update even the smallest detail on such a site, you will either have to dig into the code yourself, or, if you do not know HTML and CSS yourself, you will need to resort to the services of a webmaster every time.

  3. Stagnation of content.
  4. Due to the fact that the content of such a site is updated very rarely, the content on them “stagnates”, this has a very unfavorable effect on search engines. Of course, you can promote such a site, but mainly through paid methods.

Dynamic websites examples

On the other hand, dynamic sites can cost much more, especially if they are developed from scratch. Also, hosting will be a little more expensive, since you will need to connect additional features. But the numerous advantages of dynamic sites more than offset these disadvantages.

A dynamic website gives its owner the ability to update and add content to their site very easily. For example, news and events can be added through the admin panel in the browser itself, without the need to edit code files.

The possibilities of a dynamic website are limited only by our imagination.

Examples of dynamic sites are sites based on management systems, online stores, classifieds sites, forums, sites with opportunities for clients and visitors to leave reviews, comments, upload files, etc.

Advantages of dynamic sites:

  1. More functional site.
  2. It's much easier to update it.
  3. Constant updating has a positive effect on website promotion and brings more visitors.
  4. Such a site helps its owner and gives much more opportunities to communicate with his audience and make his site more interesting for visitors through various functions.

conclusions

So, we see that a dynamic site has much greater development prospects than a static one, despite the fact that it may take more time to bring such a site to life.

More and more people are realizing the undeniable advantage of dynamic sites, and therefore more and more of them are appearing on the Internet.

But on the other hand, it all depends on what YOU specifically need, if you need, for example, a one-page website through which you will sell some product, or a business card website from 1 to 5-6 pages, which you do not If you plan to constantly update, then a completely natural solution would be to opt for a static site.

If you want your project to constantly develop and be filled with content, then, of course, you need a dynamic website.