How to use shell to write CGI programs

Source: Internet
Author: User

I used shell to write some CGI examples. I would like to introduce it to you today.

CGI is an interface standard that does not distinguish programming languages. That is to say, CGI can be written in any language as long as it has standard input, output, and environment variables. CGI redirects the standard output to the HTTP Response and returns it to the browser.

CGI strictly introduces the public Gateway Interface CGI (Common
As one of the most important technologies in WWW technology, gatewayinterface plays an irreplaceable role. CGI is the interface standard between external applications (CGI programs) and Web servers. It is the procedure for transmitting information between CGI programs and web servers. CGI specifications allow the Web server to execute external programs and send their output to the web browser. cgi converts a simple set of static hypermedia documents on the Web into a complete new interactive media.

......

The following describes how to use shell to write a CGI.

For CGI, the most important thing is to receive the user's request and parse the parameters passed by the get or POST method from the request. This, I think, is also the most troublesome for beginners. Here we provide a script that has completed this function-proccgi. Sh (the download URL will be provided later ). This script can directly parse the data transmitted by the get and post methods.

Usage:

Call eval' in the CGI shell script '. /proccgi. sh $ * 'statement, and then use "$ from _" and the key of the parameter to obtain the parameter value, for example, task_id = "$ form_taskid ".

It is the simplest CGI program of shell, and transmits taskid = XXXX from the foreground to the CGI program. CGI calls the proccgi. Sh script to parse the taskid value and store it in the variable from_taskid. In this way, the value of taskid is obtained. Next, print task_id is to output the value of task_id to the standard output. By now, all CGI programs are finished. cgi regards all the content printed to the standard output as HTTP response, return to the browser.

Someone may be surprised that this is a simple shell script. How can it be used as CGI. As mentioned above, CGI is an interface standard. As long as the program outputs content to the standard output, the first line is "Content-Type: text/html; charset = UTF-8 \ n "can be used as CGI. If you don't believe it, you can try it in this language. Of course, the compiled CGI must be placed under the Apache executable directory. Otherwise, the CGI cannot be accessed through the URL.

Finally, the CGI name is changed to xxxx. cgi after writing CGI at the company. You can modify a script or binary program in this way. In fact, there is no rule to reserve. .exe,. Sh, or. py. cgi can still be executed.

In fact, CGI is an executable program in the background.

Original article, reprinted Please note:Reprinted from the growth penguin

Link: How to use shell to write CGI programs

About me:Introduction to growth penguins

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.