Unlimited commerce cgi. E-Commerce - what is it? E-Commerce Partners Network is an affiliate program of the largest online stores. Installing CGI on Macintosh

E-commerce in clear Russian. How does online business work?

Lately, there have been more and more projects related to online trading. While studying this area, I could not find a general and understandable description of the process. Therefore, I decided to make something like a cheat sheet that you can always refer to in order to understand the procedure in such an area as e-commerce.

I’ll immediately make a reservation that I focused on the processes and channels that help bring in clients.

E-commerce: what is it about?

Definitions from various sources say something about selling goods or services via the Internet. In simple words, e-commerce is any online activity where money appears.

Shopping, selling, insurance, banking, electronic money, everything is here. Take it and sign it.

From the target

In order to understand the issue, I suggest starting the path from the very end. What is the goal of any business? That's right, make money. So, imagine any product, for example, silicone socks. Why not!

I took the first thing that came to mind, it turned out there was something like this...

Our task is to make money on these socks. We are thinking about the Internet. Hmm...why not build a website and that’s how the sales will go, just keep me Maldives! But it's not that simple.

I really like to draw. This helps to understand the various processes. Let's draw?!

So far our model looks like this. We take socks, put them on the Internet and get money. This is simply great! Your eyes are burning, your palms are sweating and you already want to get down to business. But do you need to make a website or a sales platform?

Website or platform for sale

There are various solutions for placing your product on the World Wide Web. You can create your own website or use third-party platforms (groups, pages on social networks, message boards, etc.). Let's stop at the site.

You ordered a website, took a ready-made template, or created it yourself using a website builder (you can google CMS), it doesn’t matter. Then they placed a bunch of silicone socks of different types and were happy.

Sorry to interrupt reading. Join my telegram channel. Fresh announcements of articles, development of digital products and growth hack, it’s all there. Waiting for you! Let's continue...

Payment systems

But in order for a person to buy from you here and now, it will be necessary to tweak the payment systems. This is a kind of service that allows you to make purchases online through: bank cards, Internet money, mobile phones and a bunch of other things. For this you will have to share a percentage of the transactions, but this way you will make your life much easier.

Choose the service that suits you. Somewhere the percentage will be higher, and somewhere there will be a subscription or something else. Just do a little research. Put the required code on your website, link all transactions to your card account and voila!

That would seem to be all. There is a website, product cards too, and even the “buy” button works, but something is missing... There is no flow of customers who will buy.

Customer flows

Where: CAC = Cost of acquiring a new customer. MCC (marketingcampaign costs) = The total cost of marketing expenses aimed at attracting customers (but not retaining them). W (wages) = Salary for marketers and sales managers. S (software) = The cost of software used in advertising and sales (for example, the sales platform used, marketing automation, A/B testing, analytics services, etc.). PS (professionalservices) = Cost of professional services provided to marketing and sales departments (design, consulting, etc.). O (other) = Other overhead costs related to the marketing and sales departments. CA (customersacquired) = Total number of attracted customers.

But we must not forget about the quality of the client; LTV will help here.

Important metrics: LTV

Live Time Value, the customer life cycle, is another indicator in e-commerce that needs to be taken into account. It shows how much income one client brings in on average. There are different approaches to calculation, I chose the actual one based on profit, as one of the most accurate.

This is simply the sum of the total revenue over the entire purchase history for each individual customer. Add the sum of all customer purchases (transactions) to transaction N, where transaction N is the last purchase the customer made with your company. If you have access to all customer transaction data, then you can easily calculate this using Excel.

LTV = (transaction 1 + transaction 2 + transaction 3... + transaction N) x profit share in revenue.

Calculating LTV based on net profit ultimately shows the actual profit a customer brings to your company. This takes into account the cost of customer service, the cost of retention, the cost of attraction, etc. The result is a whole complex of calculations based on individual data. The total profit generated per customer over time will give you an accurate understanding of the profitability of your customers to date.

Other approaches can be found at.

Important indicators: CAC and LTV ratio

To understand the viability of a business, it is very important to look at the ratio of the two mentioned CAC:LTV ratios.

  • Less than 1:1 - You are rushing at full speed towards bankruptcy.
  • 1:1 – You lose money on every attracted client.
  • 1:2 – It seems good, but it seems that you are not investing enough money, and you could develop faster. Launch more aggressive customer acquisition campaigns and achieve rates close to 1:3.
  • 1:3 – Ideal ratio. You have a thriving business and a strong business model.

Important indicators: ROI do not forget

As we discussed above, in e-commerce you need to clearly understand whether it is profitable to use an acquisition channel or not. In addition to LTV and CAC, there is another important indicator: ROI. It shows whether your investment, in our case in advertising, has paid off. That is. how much 1 invested ruble brought us in the end.

A very simple formula is used for the calculation:

Where “Campaign Revenue” is the difference between the income from the channel and the cost of your product. And to calculate profit, subtract advertising costs.

Thus, a more detailed formula would look like this:

ROI = (Channel Revenue – Cost) – Advertising Expenses / Advertising Expenses x 100%

Read a more detailed example with calculation. In fact, this simple formula is placed in the same Excel table, where everything is calculated automatically.

All three indicators that we have discussed are important in E-commerce. Each of them allows you to find bottlenecks in your flows and work with them. This is where the growth potential for business lies. I added a little more to our model with socks.

It’s impossible to fit everything into one material, and who will read it for so long? Later I will make a separate guide on the nuances of e-commerce that can interfere with sales.

Total

Overall, you now have a general understanding of online trading or e-commerce. Further, as they say: “The devil is in the details.” Study each channel separately, calculate performance indicators and look for new insights in the little things. Internet sales for you, and more! And I have one more material.

Yes, I almost forgot, Happy New Year, dear readers! I wish you great victories and achievements next year!

Andover, Massachusetts, November 19, 2003

The Commerce Group, Inc. (NYSE: CGI), the largest writer of private passenger automobile insurance in Massachusetts and CGI Group Inc. (CGI) (TSX: GIB.A; NYSE: GIB;), a leading provider of information technology and business processing services, announced today the signing of a six-year business process outsourcing (BPO) contract renewal valued at US$35 million. CGI will provide full policy processing services for Massachusetts private passenger and commercial automobile lines as well as providing CGI's CollaborativeEdge agency interface tool, application support and maintenance, regulatory support, systems consulting, and document management services.

Gerald Fels, Commerce Group's executive vice-president and CFO, stated: "As the leading provider of private passenger automobiles in Massachusetts, our goal is to provide our agents and employees with services that help them perform to their highest level. Over the years we have fostered a strong relationship with CGI. Their system is robust and accurate and their team is very familiar with our internal processing systems. That is important for us."

Serge LaPalme, president, insurance business services for CGI added: "We are very pleased to be continuing our relationship with the Commerce Group, one that spans over 30 years. The Commerce Group continues to be one of our valued business partners and is strategic to our success. In helping our client further focus on their core business, we are taking advantage of new technologies when and where it makes sense. Our team knows the insurance industry and the State"s very unique regulatory environment intimately and as a result are quick to adapt existing solutions to this constantly evolving sector."

About The Commerce Group, Inc.

The Commerce Group, Inc., an insurance holding company, is headquartered in Webster, Massachusetts. Commerce Group"s property and casualty insurance subsidiaries include The Commerce Insurance Company and Citation Insurance Company in Massachusetts, Commerce West Insurance Company in California and American Commerce Insurance Company in Ohio. Through its subsidiaries" combined insurance activities, Commerce Group is ranked as the 22nd largest personal automobile insurance group in the country by A.M. Best, based on 2002 direct written premium information.

About CGI
Founded in 1976, CGI is the fifth largest independent information technology services firm in North America, based on its headcount. CGI and its affiliated companies employ 20,000 professionals. CGI's annualized revenue run-rate is currently CDN$2.8 billion (US$1.9 billion) and at September 30, 2003, CGI's order backlog was CDN$12.3 billion (US$9.1 billion). CGI provides end-to-end IT and business process services to clients worldwide from offices in Canada, United States and Europe. CGI's shares are listed on the TSX (GIB.A) and the NYSE (GIB) and are included in the TSX 100 Composite Index as well as the S&P/TSX Canadian Information Technology and Canadian MidCap Indices. Website: .

2012: Purchase of British Logica

In June 2012, CGI Group announced that it had signed an agreement to purchase the largest European systems integrator Logica. The transaction amount is 2.8 billion Canadian dollars ($2.7 billion). As part of the agreements reached, CGI also agreed to assume obligations to repay Logica's debt in the amount of C$515 million.

To finance the transaction, CGI plans to raise 1 billion Canadian dollars by issuing an additional 46.7 million shares, borrow 2 billion Canadian dollars from the Canadian Imperial Bank of Commerce, National Bank of Canada and The Toronto-Dominion Bank, and about 650 million Canadian dollars more. dollars - within the current credit line.

The proposed price per share was 59.8% higher than Logica's closing price on May 30, 2012. The deal represents approximately 6.6 times Logica's earnings before interest, taxes, depreciation and amortization (EBITDA) for the year. 12 month period ended December 31, 2011

The acquisition of Logica is expected to boost CGI's earnings per share by 25% to 30%, excluding acquisition and integration costs. As a result of the merger, the resulting company's workforce and annual revenues will be more than double those of CGI. The size of the combined company's staff will be about 72 thousand employees located in offices in 43 countries, and annual revenue will be about 10.4 billion Canadian dollars ($9.6 billion).

The new company will be the sixth largest among the world's IT consultants. The largest of these are IBM, Accenture, Cap Gemini, Tata Consultancy and Infosys, according to Reuters estimates.

"Logica is a leading business and technology services company with dedicated professionals and trusted, long-term clients," said CGI President and CEO Michael Roach. "We are confident we are doing the right thing." By acquiring Logica, we are acquiring it at the right price and at the right time to create one of the few largest independent providers of end-to-end technology services."

CGI's board of directors unanimously approved the transaction. It is planned to be completed by September 2012, after receiving shareholder approval and completing standard procedures. The company integration process is planned to be completed within 3 years

Thanks to the World Wide Web, almost anyone can provide information online in a form that is easy on the eyes and can be widely disseminated. You've no doubt surfed the Internet and seen other sites, and now you probably know that scary acronyms like "HTTP" and "HTML" are simply shorthand for "Web" and "the way information is expressed on the Internet." You may already have some experience presenting information on the Internet.

The Internet has proven to be an ideal medium for distributing information, as can be seen from its enormous popularity and widespread development. Although some have questioned the usefulness of the Internet and attribute its widespread development and popularity mainly to intrusive advertising, the Internet is undeniably an important medium for presenting all kinds of information. Not only are there many services available to provide up-to-date information (news, weather, live sporting events) and reference material electronically, there are also significant amounts of other types of data available. The IRS, which distributed all of its 1995 tax return forms and other information via the World Wide Web, recently admitted to receiving fan mail for its Web site. Who would have thought that the IRS would ever receive fan mail? This was not because his site was well designed, but because it had proven to be a truly useful tool for thousands, perhaps millions, of people.

What makes the Web unique and such an attractive information service? First of all, it provides a hypermedia interface to data. Think about your computer's hard drive. Typically, data is expressed in a linear fashion, similar to a file system. For example, you have a number of folders, and inside each folder there are either documents or other folders. The web uses a different paradigm to express information called a hypermedia. A hypertext interface consists of a document and links. Links are words that are clicked to see other documents or find other types of information. The Web expands the concept of hypertext to include other types of media, such as graphics, sounds, video (hence the name "hypermedia"). Selecting text or graphics on a document allows you to see related information about the selected item in any number of forms.

Almost everyone can benefit from this simple and unique way of presenting and distributing information, from academics who want to immediately use data with their colleagues to business people who share information about their company with everyone. However, although giving information is extremely important, in the last few years many have felt that receiving information is an equally important process.

Although the Web provides a unique hypermedia interface for information, there are many other effective ways to distribute data. For example, network services such as File Transfer Protocol (FTP) and the Gopher newsgroup existed long before the World Wide Web. Electronic mail has been the primary medium for communication and information exchange on the Internet and most other networks almost from the very beginning of these networks. Why has the Internet become such a popular way of distributing information? The multimedia aspect of the Internet has contributed significantly to its unprecedented success, but for the Internet to be most effective, it must be interactive.

Without the ability to receive user input and provide information, the Web would be a completely static environment. The information would only be available in the format specified by the author. This would undermine one of the capabilities of computing in general: interactive information. For example, rather than forcing the user to view multiple documents as if he or she were looking through a book or dictionary, it would be better to allow the user to identify keywords on a topic of interest. Users can customize the presentation of data rather than relying on a rigid structure defined by the content provider.

The term "Web server" can be misleading because it can refer to both the physical machine and the software it uses to communicate with Internet browsers. When a browser requests a given Web address, it first connects to the machine via the Internet, sending the Web server software a request for the document. This software runs continuously, waiting for such requests to arrive and responding accordingly.

Although servers can send and receive data, the server itself has limited functionality. For example, the most primitive server can only send the required file to the browser. The server usually does not know what to do with this or that additional input. If the ISP does not tell the server how to handle this additional information, the server will most likely ignore the input.

In order for the server to be able to perform other operations besides searching and sending files to the Internet browser, you need to know how to expand the functionality of the server. For example, a Web server cannot search a database based on a keyword entered by a user and return multiple matching documents unless such a capability has been programmed into the server in some way.

What is CGI?

The Common Gateway Interface (CGI) is an interface to the server that allows you to extend the functionality of the server. Using CGI, you can interact interactively with users who access your site. At a theoretical level, CGI allows the server to be able to parse (interpret) input from the browser and return information based on the user's input. On practical level,CGI is an interface that allows the programmer to write ,programs that communicate easily with the server.

Typically, to expand the server's capabilities, you would have to modify the server yourself. This solution is undesirable because it requires understanding the lower layer of Internet Protocol network programming. This would also require editing and recompiling the server source code or writing a custom server for each task. Let's say we want to extend the server's capabilities so that it acts as a Web-to-e-mail gateway, taking user-entered information from the browser and sending it over e-mail to another user. The server would have to insert code to parse the input from the browser, forward it via email to the other user, and forward the response back to the browser over the network connection.

Firstly, such a task requires access to the server code, which is not always possible.

Secondly, it is difficult and requires extensive technical knowledge.

Third, this only applies to a specific server. If you need to move your server to another platform, you will have to run or at least spend a lot of time porting code to that platform.

Why CGI?

CGI offers a portable and simple solution to these problems. The CGI protocol defines standard way for programs to contact the Web server. Without any special knowledge, you can write a program in any machine language that interfaces and communicates with the Web server. This program will work with all Web servers that understand the CGI protocol.

CGI communication is done using standard input and output, which means that if you know how to print and read data using your programming language, you can write a Web server application. Apart from parsing input and output, programming CGI applications is almost equivalent to programming any other application. For example, to program the "Hello, World!" program, you use your language's print functions and the format defined for CGI programs to print the appropriate message.

Selecting a programming language

Because CGI is a universal interface, you are not limited to any specific machine language. An important question that is often asked is: what programming languages ​​can be used for CGI programming? You can use any language that allows you to do the following:

  • Print to standard output
  • Read from standard input
  • Read from variable modes

Almost all programming languages ​​and many scripting languages ​​do these three things, and you can use any of them.

Languages ​​fall into one of the following two classes: translated and interpreted. A translated language such as C or C++ is usually smaller and faster, while interpreted languages ​​such as Perl or Rexx sometimes require a large interpreter to be loaded upon startup. Additionally, you can distribute binary codes (code that translates into machine language) without source code if your language is translatable. Distributing interpretable scripts usually means distributing source code.

Before choosing a language, you first need to consider your priorities. You need to weigh the benefits of the speed and efficiency of one programming language against the ease of programming of another. If you have a desire to learn another language, instead of using the one you already know, carefully weigh the advantages and disadvantages of both languages.

The two most commonly used languages ​​for CGI programming are C and Perl (both of which are covered in this book). Both have clear advantages and disadvantages. Perl is a very high-level language, and at the same time a powerful language, especially suitable for parsing text. Although its ease of use, flexibility, and power make it an attractive language for CGI programming, its relatively large size and slower operation sometimes make it unsuitable for some applications. C programs are smaller, more efficient, and provide lower-level system control, but are more complex to program, do not have lightweight built-in text processing routines, and are more difficult to debug.

Which language is most suitable for CGI programming? The one that you consider more convenient from a programming point of view. Both are equally effective for programming CGI applications, and with the proper libraries, both have similar capabilities. However, if you have a hard-to-reach server, you can use smaller, translated C programs. If you need to quickly write an application that requires a lot of text processing work, you can use Perl instead.

Cautions

There are some important alternatives to CGI applications. Many servers now include API programming, which makes it easier to program direct server extensions as opposed to standalone CGI applications. API servers are generally more efficient than CGI programs. Other servers include built-in functionality that can handle special non-CGI elements, such as database linking. Finally, some applications can be handled by some new client-side (rather than server-side) technologies like Java. With such rapid changes in technology, will CGI quickly become obsolete?

Hardly. CGI has several advantages over newer technologies.

  • It is versatile and portable. You can write a CGI application using almost any programming language on any platform. Some of the alternatives, such as the server API, limit you to certain languages ​​and are much more difficult to learn.
  • It is unlikely that client-side technologies such as Java will replace CGI, because there are some applications that server-side applications are much better suited to run.
  • Many of the limitations of CGI are limitations of HTML or HTTP. As Internet standards as a whole evolve, so do CGI capabilities.

Summary

The Common Gateway Interface is the protocol by which programs interact with Web servers. The versatility of CGI gives programmers the ability to write gateway programs in almost any language, although there are many trade-offs associated with different languages. Without this ability, creating interactive Web pages would be difficult, at best requiring server modifications, and interactivity would be unavailable to most users who are not site administrators.

Chapter 2: Basics

Several years ago, I created a page for a college at Harvard where people could submit comments about them. At the time, the Internet was young and documentation was scarce. I, like many others, relied on short documentation and programming systems created by others to teach myself CGI programming. Although this method of study required some searching, many experiments, and created many questions, it was very effective. This chapter is the result of my early work with CGI (with a few tweaks, of course).

Although it takes some time to fully understand and master the common gateway interface, the protocol itself is quite simple. Anyone who has some basic programming skills and is familiar with the Web can quickly learn to program fairly complex CGI applications just as I and others learned to do several years ago.

The purpose of this chapter is to present the basics of CGI in a comprehensive, albeit condensed, way. Each concept discussed here is presented in detail in subsequent chapters. However, after completing this chapter, you can immediately begin programming CGI applications. Once you reach this level, you can learn the intricacies of CGI, either by reading the rest of this book or simply experimenting on your own.

You can boil down CGI programming to two tasks: receiving information from the Web browser and sending information back to the browser. This is done quite intuitively once you become familiar with the normal use of CGI applications. Often the user is asked to fill out some form, for example, insert his name. Once the user fills out the form and presses Enter, this information is sent to the CGI program. The CGI program must then convert this information into something it understands, process it accordingly, and then send it back to the browser, be it a simple confirmation or the result of a search in a multi-purpose database.

In other words, programming CGI requires understanding how to receive input from the Internet browser and how to send output back. What happens between the input and output stages of a CGI program depends on the developer's goal. You'll find that the main difficulty in CGI programming lies in this intermediate stage; Once you learn how to work with input and output, that's essentially enough to become a CGI developer.

In this chapter, you'll learn the principles behind CGI input and output, as well as other basic skills you'll need to write and use CGI, including things like creating HTML forms and naming your CGI programs. This chapter covers the following topics:

  • Traditional program "Hello, World!";
  • CGI Output: Sending information back for display in an Internet browser;
  • Configuring, installing, and running the application. You will learn about different Web platforms and servers;
  • CGI Input: Interpretation of information sent by the Web browser. Introduction to some useful programming libraries for parsing such input;
  • A simple example: it covers all the lessons in a given chapter;
  • Programming strategy.

Due to the nature of this chapter, I only touch lightly on some topics. Don't worry; All of these topics are covered in much more depth in other chapters.

Hello, World!

You start with a traditional introductory programming problem. You will write a program that displays "Hello, World!" on your Web browser. Before you write this program, you must understand what information the Web browser expects to receive from CGI programs. You also need to know how to run this program so you can see it in action.

CGI is language independent, so you can implement this program in any language. Several different languages ​​are used here to demonstrate the independence of each language. In Perl, the "Hello, World!" program shown in Listing 2.1.

Listing 2.1. Hello, World! in Perl. #!/usr/local/bin/perl # Hello.cgi - My first CGI program print "Content-Type: text/html\n\n"; print " \n"; print " Hello, World!"; print "\n"; print " \n"; print "

Hello, World!

\n"; print "

\n";

Save this program as hello.cgi, and install it in the appropriate location. (If you're not sure where it is, don't worry; you'll find out in the "Installing and Running a CGI Program" section later in this chapter.) For most servers, the directory you need is cgi-bin. Now, call the program from your Web browser. For most, this means opening the following uniform resource locator (URL):

http://hostname/directoryname/hello.cgi

Hostname is the name of your Web server, and directoryname is the directory where you put hello.cgi (probably cgi-bin).

Splitting hello.cgi

There are a few things to note about hello.cgi.

First, you use simple print commands. CGI programs do not require any special file descriptors or output descriptors. To send output to the browser, simply print to stdout.

Second, note that the content of the first print statement (Content-Type: text/html) does not appear on your Web browser. You can send any information you want back to the browser (HTML page, graphics or sound), but first, you need to tell the browser what kind of data you are sending it. This line tells the browser what kind of information to expect - in this case, an HTML page.

Thirdly, the program is called hello.cgi. You don't always need to use the .cgi extension with the name of your CGI program. Although source for many languages ​​also uses the .cgi extension, this is not used to indicate the type of language, but is a way for the server to identify the file as executable file, not a graphic file, HTML file, or text file. Servers are often configured to only attempt to execute those files that have this extension, displaying the contents of all others. Although using the .cgi extension is not required, it is still considered good practice.

In general, hello.cgi consists of two main parts:

  • tells the browser what information to expect (Content-Type: text/html)
  • tells the browser what to display (Hello, World!)

Hello, World! in C

To show the language independence of CGI programs, Listing 2.2 shows the equivalent of the hello.cgi program written in C.

Listing 2.2. Hello, World! in C. /* hello.cgi.c - Hello, World CGI */ #include int main() ( printf("Content-Type: text/html\r\n\r\n"); printf(" \n"); printf(" Hello, World!\n"); printf("\n"); printf(" \n"); printf("

Hello, World!

\n"); printf("

\n"); )

Note

Note that the Perl version of hello.cgi uses Content-Type print ": text/html\n\n "; While version C uses Printf("Content-Type: text/html\r\n\r\n");

Why does Perl print the operator end with two newlines (\n) while C printf ends with two carriage returns and newlines (\r\n)?

Technically, headers (all output before the blank line) are expected to be separated by carriage returns and newlines. Unfortunately, on DOS and Windows machines, Perl translates \r as another newline rather than as a carriage return.

Although Perl's \rs exception is technically incorrect, it will work on almost all protocols and is equally portable across all platforms. Therefore, in all the Perl examples in this book, I use newline separating headers rather than carriage returns and newlines.

An appropriate solution to this problem is presented in Chapter 4, Conclusion.

Neither the Web server nor the browser cares what language is used to write the program. Although each language has advantages and disadvantages as a CGI programming language, it is best to use the language that you are most comfortable working with. (The choice of programming language is discussed in more detail in Chapter 1, “Common Gateway Interface (CGI)”).

CGI rendering

Now you can take a closer look at the issue of sending information to the Web browser. From the "Hello, World!" example, you can see that Web browsers expect two sets of data: a header, which contains information such as what information to display (eg Content-Type: line) and actual information (what the Web browser displays). These two pieces of information are separated by a blank line.

The header is called the HTTP header. It gives important information about the information that the browser is going to receive. There are several various types HTTP headers, and the most universal is the one you used before: Content-Type: header. You can use different combinations of HTTP headers, separated by carriage returns and newlines (\r\n). The blank line separating the header from the data also consists of a carriage return and a newline (why both are needed is briefly discussed in the preceding note and detailed in Chapter 4). You'll learn about other HTTP headers in Chapter 4; Currently you are dealing with Content-Type: header.

Content-Type: The header describes the type of data that the CGI returns. The appropriate format for this header is:

Content-Type: subtype/type

Where subtype/type is the correct Multipurpose Internet Mail Extensions (MIME) type. The most common MIME type is the HTML type: text/html. Table 2.1 lists a few more common MIME types that will be discussed; A more complete listing and analysis of MIME types is provided in Chapter 4.

Note

MIME was originally invented to describe the contents of mail message bodies. It has become a fairly common way to represent Content-Type information. You can read more about MIME in RFC1521. RFCs on the Internet stand for Requests for Comments, which are summaries of decisions made by groups on the Internet trying to set standards. You can view the results of RFC1521 at the following address: http://andrew2.andrew.cmu.edu/rfc/rfc1521.html

Table 2.1. Some common MIME types. MIME Type Description Text/html Hypertext Markup Language (HTML) Text/plain Plain text files Image/gif Graphic files GIF Image/jpeg Compressed graphic files JPEG Audio/basic Audio - Sun *.au Audio/x-wav files Windows *.wav files

After the header and an empty line, you simply print the data in the form you need. If you are sending HTML, then print HTML tags and data to stdout after the header. You can also send graphics, sound and other binary files by simply printing the contents of the file to stdout. Several examples of this are given in Chapter 4.

Installing and Running a CGI Program

This section deviates somewhat from CGI programming and talks about configuring your Web server to use CGI, installing and running programs. You'll be introduced to different servers for different platforms in more or less detail, but you'll have to dig deeper into your server's documentation to find the best option.

All servers require space for server files and space for HTML documents. In this book, the server area is called ServerRoot, and the document area is called DocumentRoot. On UNIX machines, ServerRoot is usually in /usr/local/etc/httpd/, and DocumentRoot is usually in /usr/local/etc/httpd/htdocs/. However, this will not make any difference to your system, so replace all references to ServerRoot and DocumentRoot with your own ServerRoot and DocumentRoot.

When you access files using your Web browser, you specify the file in the URL relative to the DocumentRoot. For example, if your server address is mymachine.org, then you access this file with the following URL: http://mymachine.org/index.html

Configuring the server for CGI

Most Web servers are pre-configured to allow the use of CGI programs. Typically two parameters indicate to the server whether the file is a CGI application or not:

  • Designated directory. Some servers allow you to determine that all files in a designated directory (usually called cgi-bin by default) are CGI.
  • File name extensions. Many servers have this pre-configuration that allows all files ending in .cgi to be defined as CGI.

The designated directory method is something of a relic of the past (the very first servers used it as the only method for determining which files were CGI programs), but it has several advantages.

  • It keeps CGI programs centralized, preventing other directories from becoming cluttered.
  • You're not limited to any particular filename extension, so you can name your files whatever you want. Some servers allow you to designate several different directories as CGI directories.
  • It also gives you more control over who can record CGI. For example, if you have a server and support a system with multiple users and don't want them to use their own CGI scripts without first auditing the program for security reasons, you can designate only those files in a limited, centralized directory as CGI. Users will then have to provide you with CGI programs to install, and you can first audit the code to make sure the program doesn't have any major security issues.

The CGI notation via filename extension can be useful due to its flexibility. You are not limited to one single directory for CGI programs. Most servers can be configured to recognize CGI through the filename extension, although not all are configured this way by default.

Warning

Remember the importance of security issues when you configure your server for CGI. Some tips will be covered here, and Chapter 9, Protecting CGI, covers these aspects in more detail.

Installing CGI on UNIX servers

Regardless of how your UNIX server is configured, there are several steps you need to take to ensure that your CGI applications run as expected. Your Web server will typically run as a non-existent user (that is, the UNIX user nobody - Account, which does not have access rights to the file and cannot be registered). CGI scripts (written in Perl, the Bourne shell, or another scripting language) must be executable and readable throughout the world.

Clue

To make your files world-readable and executable, use the following UNIX permissions command: chmod 755 filename.

If you are using a scripting language such as Perl or Tcl, provide the full path of your interpreter on the first line of your script. For example, a Perl script using perl in the /usr/local/bin directory would begin with the following line:

#!/usr/local/bin/perl

Warning

Never place the interpreter (perl, or Tcl Wish binary) in the /cgi-bin directory. This creates a security risk on your system. This is discussed in more detail in Chapter 9.

Some generic UNIX servers

The NCSA and Apache servers have similar configuration files because the Apache server was originally based on the NCSA code. By default, they are configured so that any file in the cgi-bin directory (located by default in ServerRoot) is a CGI program. To change the location of the cgi-bin directory, you can edit the conf/srm.conf configuration file. The format for configuring this directory is

ScriptAlias ​​fakedirectoryname realdirectoryname

where fakedirectoryname is the pseudo directory name (/cgi-bin) and realdirectoryname is the full path where the CGI programs are actually stored. You can configure more than one ScriptAlias ​​by adding more ScriptAlias ​​lines.

The default configuration is sufficient for most users' needs. You need to edit the line in the srm.conf file in either case to determine the correct realdirectoryname. If, for example, your CGI programs are located in /usr/local/etc/httpd/cgi-bin, the ScriptAlias ​​line in your srm.conf file should be something like this:

ScriptAlias ​​/cgi-bin/ /usr/local/etc/httpd/cgi-bin/

To access or link to CGI programs located in this directory, use the following URL:

Http://hostname/cgi-bin/programname

Where hostname is the name of the host of your Web server, and programname is the name of your CGI.

For example, let's say you copy the hello.cgi program to your cgi-bin directory (eg /usr/local/etc/httpd/cgi-bin) on your Web server called www.company.com. To access your CGI, use the following URL: http://www.company.com/cgi-bin/hello.cgi

If you want to configure your NCSA or Apache server to recognize any file with a .cgi extension as a CGI, you need to edit two configuration files. First, in the srm.conf file, uncomment the following line:

AddType application/x-httpd-cgi .cgi

This will associate the MIME type CGI with the .cgi extension. Now, we need to change the access.conf file so that we can run CGI in any directory. To do this, add the ExecCGI option to the Option line. It will look something like the following line:

Option Indexes FollowSymLinks ExecCGI

Now, any file with a .cgi extension is considered CGI; access it as you would any file on your server.

The CERN server is configured in the same way as the Apache and NCSA servers. Instead of ScriptAlias, the CERN server uses the Exec command. For example, in the httpd.conf file, you will see the following line:

Exec /cgi-bin/* /usr/local/etc/httpd/cgi-bin/*

Other UNIX servers can be configured in the same way; This is described in more detail in the server documentation.

Installing CGI on Windows

Most servers available for Windows 3.1, Windows 95 and Windows NT are configured using the "file name extension" method for CGI recognition. In general, changing the configuration of a Windows-based server simply requires running the server configuration program and making the appropriate changes.

Sometimes configuring a server to run a script (such as Perl) correctly can be difficult. In DOS or Windows, you will not be able to specify the interpreter on the first line of the script, as is the case with UNIX. Some servers have a predefined configuration to associate certain filename extensions with the interpreter. For example, many Windows Web servers assume that files ending in .pl are Perl scripts.

If the server does not perform this type of file association, you can define a packager batch file that calls both the interpreter and the script. As with the UNIX server, do not install the interpreter in either the cgi-bin directory or any Web-accessible directory.

Installing CGI on Macintosh

The two most well-known server options for the Macintosh are WebStar StarNine and its predecessor MacHTTP. Both recognize CGI by its filename extension.

MacHTTP understands two different extensions: .cgi and .acgi, which stands for asynchronous CGI. Regular CGI programs installed on a Macintosh (with a .cgi extension) will keep the Web server in a busy state until the CGI finishes running, causing the server to suspend all other requests. Asynchronous CGI, on the other hand, allows the server to accept requests even while it is running.

A CGI Macintosh developer using any of these Web servers should, if possible, use just the .acgi extension rather than the .cgi extension. It should work with most CGI programs; if it doesn't work, rename the program to .cgi.

Executing CGI

Once you have installed CGI, there are several ways to execute it. If your CGI program is an output-only program, such as the Hello,World! program, then you can execute it simply by accessing its URL.

Most programs run as a server application on an HTML form. Before learning how to get information from these forms, first read a short introduction about creating such forms.

A quick tutorial on HTML forms

The two most important tags in an HTML form are the

And . You can create most HTML forms using just these two tags. In this chapter, you will explore these tags and a small subset of possible types or attributes. . Complete guide and link to HTML forms are found in Chapter 3, HTML and Forms.

Tag

Tag used to determine which part of the HTML file should be used for user-entered information. This refers to how most HTML pages call a CGI program. Tag attributes specify the program's name and location - either locally or as a full URL, the type of encoding used, and the data movement method used by the program.

The next line shows the specifications for the tag :

< ACTION FORM = "url" METHOD = ENCTYPE = "..." >

The ENCTYPE attribute does not play a special role and is usually not included with the tag . Detailed information regarding the ENCTYPE tag is given in Chapter 3. One way to use ENCTYPE is shown in Chapter 14, "Branded Extensions."

The ACTION attribute refers to the URL of the CGI program. Once the user fills out the form and provides information, all information is encoded and transferred to the CGI program. The CGI program itself solves the problem of decoding and processing information; This aspect is discussed in "Accepting Input from the Browser," later in this chapter.

Finally, the METHOD attribute describes how the CGI program should receive input. The two methods, GET and POST, differ in how they pass information to the CGI program. Both are discussed in "Accepting Input from the Browser."

In order for the browser to allow user input, all form tags and information must be surrounded by the tag . Don't forget the closing tag

to indicate the end of the form. You cannot have a form within a form, although you can set up a form that allows you to present pieces of information in different places; this aspect is discussed extensively in Chapter 3.

Tag

You can create text input bars, radio buttons, checkboxes, and other means of accepting input using the tag . This section covers only text input fields. To implement this field, use the tag with the following attributes:

< INPUT TYPE=text NAME = "... " VALUE = "... " SIZE = MAXLENGTH = >

NAME is the symbolic name of the variable that contains the value entered by the user. If you include text in the VALUE attribute, that text will be placed as default in the text input field. The SIZE attribute allows you to specify the horizontal length of the input field as it will appear in the browser window. Finally, MAXLENGTH specifies the maximum number of characters the user can enter into the field. Please note that the VALUE, SIZE, MAXLENGTH attributes are optional.

Form Submission

If you have only one text field within a form, the user can submit the form by simply typing information on the keyboard and pressing Enter. Otherwise, there must be some other way for the user to present the information. The user submits information using a submit button with the following tag:

< Input type=submit >

This tag creates a Submit button inside your form. When the user finishes filling out the form, he or she can submit its contents to the URL specified by the form's ACTION attribute by clicking the Submit button.

Accepting input from the browser

Above were examples of recording a CGI program that sends information from the server to the browser. In reality, a CGI program that only outputs data does not have many applications (some examples are given in Chapter 4). The more important ability of CGI is to receive information from the browser - the feature that gives the Web its interactive character.

The CGI program receives two types of information from the browser.

  • First, it obtains various pieces of information about the browser (its type, what it can view, the host host, and so on), the server (its name and version, its execution port, and so on), and the CGI program itself ( program name and where it is located). The server gives all this information to the CGI program through environment variables.
  • Second, the CGI program can receive user input. This information, after being encoded by the browser, is sent either through an environment variable (GET method) or through standard input (stdin - POST method).

Environment Variables

It is useful to know what environment variables are available to a CGI program, both during training and for debugging. Table 2.2 lists some of the available CGI environment variables. You can also write a CGI program that outputs environment variables and their values ​​to a Web browser.

Table 2.2. Some Important CGI Environment Variables Environment Variable Purpose REMOTE_ADDR IP address of the client machine. REMOTE_HOST The host of the client machine. HTTP _ACCEPT Lists the MIME data types that the browser can interpret. HTTP _USER_AGENT Browser information (browser type, version number, operating system, etc.). REQUEST_METHOD GET or POST. CONTENT_LENGTH The size of the input if sent via POST. If there is no input or if the GET method is used, this parameter is undefined. QUERY_STRING Contains the input information when it is passed using the GET method. PATH_INFO Allows the user to specify the path from command line CGI (for example, http://hostname/cgi-bin/programname/path). PATH_TRANSLATED Translates the relative path in PATH_INFO to an actual path on the system.

To write a CGI application that displays environment variables, you need to know how to do two things:

  • Define all environment variables and their corresponding values.
  • Print results to the browser.

You already know how to perform the last operation. In Perl, environment variables are stored in the associative array %ENV, which is introduced by the name environment variable. Listing 2.3 contains env.cgi, a Perl program that accomplishes our goal.

Listing 2.3. A Perl program, env.cgi, that prints out all the CGI environment variables.

#!/usr/local/bin/perl print "Content-type: text/html\n\n"; print " \n"; print " CGI Environment\n"; print "\n"; print " \n"; print "

CGI Environment

\n"; foreach $env_var (keys %ENV) ( print " $env_var= $ENV($env_var)
\n"; ) print "

\n";

A similar program could be written in C; the complete code is in Listing 2.4.

Listing 2.4. Env.cgi.c in C. /* env.cgi.c */ #include extern char **environ; int main() ( char **p = environ; printf("Content-Type: text/html\r\n\r\n"); printf(" \n"); printf(" CGI Environment\n"); printf("\n"); printf(" \n"); printf("

CGI Environment

\n"); while(*p != NULL) printf("%s
\n",*p++); printf("

\n"); )

GET or POST?

What's the difference between the GET and POST methods? GET passes the encoded input string through the QUERY_STRING environment variable, while POST passes it through stdin. POST is the preferred method, especially for forms with a lot of data, because there are no restrictions on the amount of information sent, while with the GET method the amount of media space is limited. GET does however have a certain useful property; this is covered in detail in Chapter 5, Input.

To determine which method is used, the CGI program checks the environment variable REQUEST_METHOD, which will be set to either GET or POST. If it is set to POST, the length of the encoded information is stored in the CONTENT_LENGTH environment variable.

Coded Input

When a user submits a form, the browser first encodes the information before sending it to the server and then to the CGI application. When you use the tag , each field is given a symbolic name. The value entered by the user is represented as the value of the variable.

To determine this, the browser uses a URL encoding specification, which can be described as follows:

  • Separates different fields with an ampersand (&).
  • Separates the name and values ​​with equal signs (=), with the name on the left and the value on the right.
  • Replaces spaces with plus signs (+).
  • Replaces all "abnormal" characters with a percent sign (%) followed by a two-digit hex code for the character.

Your final encoded string will be similar to the following:

Name1=value1&name2=value2&name3=value3 ...

Note: Specifications for URL encoding are found in RFC1738.

For example, let's say you had a form that asked for name and age. The HTML code that was used to display this form is shown in Listing 2.5.

Listing 2.5. HTML code to display the name and age form.

Name and Age

Enter your name:

Enter your age:



Let's say the user enters Joe Schmoe in the name field and 20 in the age field. The input will be encoded in the input string.

Name=Joe+Schmoe&age=20

Parsing input

For this information to be useful, you need to use the information on something that can be used by your CGI programs. Strategies for parsing input are covered in Chapter 5. In practice, you will never have to think about how to parse input, because several experts have already written libraries that do the parsing, accessible to everyone. Two such libraries are presented in this chapter in the following sections: cgi -lib.pl for Perl (written by Steve Brenner) and cgihtml for C (written by me).

The general goal of most libraries written in various languages ​​is to parse an encoded string and put name and value pairs into a data structure. There is an obvious advantage to using a language that has built-in data structures like Perl; however, most libraries for low-level languages ​​such as C and C++ include data structure and subroutine execution.

It is not necessary to achieve a complete understanding of libraries; it's more important to learn how to use them as tools to make the CGI programmer's job easier.

Cgi-lib.pl

Cgi-lib.pl uses Perl associative arrays. The &ReadParse function parses the input string and enters each name/value pair by name. For example, the corresponding Perl strings needed to decode the "name/age" input string just presented would be

&ReadParse(*input);

Now, to see the value entered for "name", you can access the associative array $input("name"). Similarly, to access the value of "age", you need to look at the variable $input ("age").

Cgihtml

C doesn't have any built-in data structures, so cgihtml implements its own linklist for use with its CGI parsing routines. This defines the entrytype structure as follows:

Typedef struct ( Char *name; Char *value; ) Entrytype;

To parse the input string "name/age" in C using cgihtml, the following is used:

/* declare linked list, called input */ Llist input; /* parse input and location in linked list */ read_cgi_input(&input);

To access age information, you can either parse the list manually or use the available cgi _val() function.

#include #include Char *age = malloc(sizeof(char)*strlen(cgi_val(input, "age")) + 1); Strcpy(age, cgi_val(input, "age"));

The "age" value is now stored in the age string.

Note: Instead of using a simple array (like char age ;), I'm dynamically allocating memory space for the string age. Although this makes programming more difficult, it is nevertheless important from a security point of view. This is discussed in more detail in Chapter 9.

A simple CGI program

You are going to write a CGI program called nameage.cgi that handles the name/age form. Data processing (what I usually call "stuff in between") is minimal. Nameage.cgi simply decodes the input and displays the user's name and age. While there isn't much use for such a tool, it does demonstrate the most critical aspect of CGI programming: input and output.

You use the same form as above, calling up the "name and age" fields. Don't worry about robustness and efficiency just yet; solve the existing problem in the simplest way. The Perl and C solutions are shown in Listings 2.6 and 2.7, respectively.

Listing 2.6. Nameage.cgi in Perl

#!/usr/local/bin/perl # nameage.cgi require "cgi-lib.pl" &ReadParse(*input); print "Content-Type: text/html\r\n\r\n"; print " \n"; print " Name and Age\n"; print "\n"; print " \n"; print "Hello, " . $input("name") . ". You are\n"; print $input("age") . " years old.

\n"; print "

\n";

Listing 2.7. nameage.cgi in C

/* nameage.cgi.c */ #include #include "cgi-lib.h" int main() ( llist input; read_cgi_input(&input); printf("Content-Type: text/html\r\n\r\n"); printf(" \n"); printf(" Name and Age\n"); printf("\n"); printf(" \n"); printf("Hello, %s. You are\n",cgi_val(input,"name")); printf("%s years old.

\n",cgi_val(input,"age")); printf("

\n"); )

Please note that these two programs are almost equivalent. They both contain parsing routines that occupy only one line and process the entire input (thanks to the corresponding library routines). The output is essentially a modified version of your main Hello, World! program.

Try to run the program by filling out the form and clicking the Submit button.

General programming strategy

You now know all the basic principles required for CGI programming. Once you understand how CGI receives information and how it sends it back to the browser, the actual quality of your final product depends on your general programming abilities. Namely, when you program CGI (or anything at all, for that matter), keep the following qualities in mind:

  • Simplicity
  • Efficiency
  • Versatility

The first two qualities are quite common: try to make your code as readable and efficient as possible. Versatility applies more to CGI programs than to other applications. When you start developing your own CGI programs, you will learn that there are several basic applications that everyone wants to make. For example, one of the most common and obvious tasks of a CGI program is to process a form and email the results to a specific recipient. You could have multiple separate forms processed, each with a different recipient. Instead of writing a CGI program for each individual form, you can save time by writing more general program CGI that works for all forms.

By covering all the basic aspects of CGI, I've provided you with enough information to get started with CGI programming. However, to become an effective CGI developer, you need to have a deeper understanding of how CGI communicates with the server and browser. The remainder of this book covers in detail the issues that were briefly mentioned in this chapter, as well as application development strategy and the advantages and limitations of the protocol.

Summary

This chapter briefly introduced the basics of CGI programming. You create output by formatting your data correctly and printing to stdout. Receiving CGI input is a bit more complex because it must be parsed before it can be used. Fortunately, several libraries already exist that perform parsing.

TO at this moment You should be able to get the hang of programming CGI applications fairly easily. The remainder of this book goes into more detail about specifications, tips, and programming strategies for more advanced and complex applications.

Owners of online stores are familiar with the concept of “electronic commerce” firsthand; they already know the answer to the question “e-commerce - what is it?” But if you get to the bottom of it, many nuances emerge and this term takes on a broader meaning.

E-commerce: what is it?

The general concept is as follows: e-commerce is understood as a certain approach to doing business, which involves the inclusion of a number of operations that use digital data transfer in the provision of goods or the provision of services/work, including using the Internet.

Thus, it is any commercial transaction that is carried out using an electronic means of communication.

The work scheme is arranged as follows:

  • anyone can be a blogger or any other owner of their own Internet page) registers in this system;
  • gets its own link;
  • places special code on your web page - an advertisement for the selected official partner of the e-Commerce Partners Network appears;
  • monitors website conversion;
  • earns a certain percentage for each purchase by a visitor to your website who follows an affiliate link.

WP e-Commerce

A large number of people are now passionate about e-commerce, primarily due to the desire to create their own website, a unique online store to sell their own products. To meet this growing demand, developers have focused on creating e-commerce templates. Let's look at what this is next.

One such example of template is WordPress e-commerce. It is a shopping cart plugin for WordPress (one of the most famous web resource management systems), intended primarily for creating and organizing blogs). It is provided completely free of charge and allows site visitors to make purchases on the website.

In other words, this plugin allows you to create an online store (based on WordPress). This e-commerce plugin has all the necessary tools, settings and options to suit modern needs.




Top