Deitel & Associates, Inc. Logo

Back to www.deitel.com
digg.png delicious.png blinkit.png furl.png
Internet & World Wide Web How to Program, 3/e
Internet & World Wide Web How to Program, 3/e

ISBN:
0-13-145091-3
© 2004
pages: 1420

Order
Amazon logo

This tutorial shows how to use Perl server-side includes (SSIs) to add dynamic content to a Web page. In particular, we demonstrate a Web page hit counter. The tutorial is intended for students and professionals who are already familiar with Perl programming.
Download the Code Example
[Note: This tutorial is an excerpt (Section 25.6) of Chapter 25, Perl, from our textbook Internet & World Wide Web How to Program, 3/e. This tutorial may refer to other chapters or sections of the book that are not included here. Permission Information: Deitel, Harvey M. and Paul J., INTERNET & WORLD WIDE WEB HOW TO PROGRAM, 3/E, 2004, pp.866-870. Electronically reproduced by permission of Pearson Education, Inc., Upper Saddle River, New Jersey.]
 
25.6 Server-Side Includes (Continued)
Figure 25.3 implements a Web page hit counter. Each time a client requests the document, the counter is incremented by 1. The Perl script fig25_15.pl manipulates the counter.
Fig. 25.3   Incorporating a Web-page hit counter and displaying environment variables, using server-side includes.
1   <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
2   "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
3   
4   <!-- Fig. 25.14: fig25_14.shtml -->
5   
6   <html>
7      <head>
8         <title>Using Server-Side Includes</title>
9      </head>
10   
11    <body>
12         <h3 style = "text-align: center">
13         Using Server-Side Includes
14       </h3>
15   
16        <!--#EXEC CGI="/cgi-bin/fig25_15.pl" --><br />
17   
18      The Greenwich Mean Time is
19       <span style = "color: blue">
20         <!--#ECHO VAR="DATE_GMT" -->.
21       </span><br />
22   
23      The name of this document is
24       <span style = "color: blue">
25          <!--#ECHO VAR="DOCUMENT_NAME" -->.
26      </span><br />
27   
28      The local date is
29       <span style = "color: blue">
30      <!--#ECHO VAR="DATE_LOCAL" -->.
31      </span><br />
32   
33      This document was last modified on
34      <span style = "color: blue">
35          <!--#ECHO VAR="LAST_MODIFIED" -->.
36       </span><br />
37   
38      Your current IP Address is
39       <span style = "color: blue">
40          <!--#ECHO VAR="REMOTE_ADDR" -->.
41       </span><br />
42   
43      My server name is
44       <span style = "color: blue">
45          <!--#ECHO VAR="SERVER_NAME" -->.
46       </span><br />
47   
48      And I am using the
49      <span style = "color: blue">
50         <!--#ECHO VAR="SERVER_SOFTWARE" -->
51         Web Server.
52       </span><br />
53   
54      You are using
55      <span style = "color: blue">
56         <!--#ECHO VAR="HTTP_USER_AGENT" -->.
57      </span><br />
58   
59      This server is using
60       <span style = "color: blue">
61         <!--#ECHO VAR="GATEWAY_INTERFACE" -->.
62       </span><br />
63   
64       <br /><br />
65       <div style = "text-align: center;
66                     font-size: xx-small">
67          <hr />
68         This document was last modified on
69         <!--#ECHO VAR="LAST_MODIFIED" -->.
70       </div>
71     </body>
72   </html>

executes the fig25_15.pl script, using the EXEC command. Before the XHTML document is sent to the client, the SSI command is executed, and any script output is sent to the client.
Page 1 | 2 | 3 | 4
Return to Tutorial Index