C Language Programming CGI program (bottom)

Source: Internet
Author: User
Tags html form

In the <<c language writing CGI program >>, we probably know how CGI works. Today we look at the C language written by CGI, how to deal with the data.
In C, the getenv ("Environment variables") function is adopted to get the data that the page transmits to the CGI, which is usually returned to the page by printf ().
the environment variables in the C language include:
Http-referer: The URL of the Web page that called the CGI program.
Remote-host: The machine name and domain name of the Web browser that called the CGI program.
Request-method: Refers to the method used when the Web server passes data to a CGI program, divided into get and post two methods. The Get method passes data to the CGI program only through environment variables (such as query-string), and the Post method passes data to the CGI program through environment variables and standard inputs, so the post method can easily pass more data to the CGI program.
Script-name: The name of the CGI program.
Query-string: When using the Post method, the data in the form is finally placed in the query-string and passed to the CGI program.
Content-type: MIME type passed to CGI program data, usually 〃applica Tion/x-www-form-url Encodede〃, which is a data encoding type that passes data from the HTML form to the CGI program with the Post method, Called the URL encoding type.

Content-length: Number of data characters (bytes) passed to the CGI program.

By example, you can better understand the CGI and how it works.
1. Build a Web server
Our selection of webserver is a lightweight server mongoose. Mongoose Source: http://pan.baidu.com/s/1mg0vs4w
Mongoose is an open source project and is interested to study it.
Compiling the source code under the Linux system: Make Linux
650) this.width=650; "Src=" http://b145.photo.store.qq.com/psb?/5d11cec8-02fc-41d1-820a-68ed5b627c57/ xubheuecfu1icihgewjsutiozglsvuhdw4xjacbhhho%21/b/da0ddvakhqaa&ek=1&kp=1&pt=0&bo= Xgi6aaaaaaafaeu%21&su=0116664353&sce=0-12-12&rf=2-9 "height=" "width=" 606 "alt=" DA0DdVaKHQAA&ek =1&kp=1&pt=0&bo=xgi6aaaaa "/>

Run the command by running the./mongoose boot server or./mongoose & background.
Enter the http://IP:8080 test server:
650) this.width=650; "Src=" http://b132.photo.store.qq.com/psb?/5d11cec8-02fc-41d1-820a-68ed5b627c57/0os* Gutufmr4bqx3ya1yolzg85ljg4.ocy466fuiu6e%21/b/dc9uu04skgaa&ek=1&kp=1&pt=0&bo=4afiaqaaaaafais%21 &su=048898353&sce=0-12-12&rf=2-9 "height=" 328 "width=" 480 "alt=" dc9uu04skgaa&ek=1&kp=1&pt =0&bo=4afiaqaaa "/>

2. Write the index.html page with the following code:
650) this.width=650; "Src=" http://b148.photo.store.qq.com/psb?/5d11cec8-02fc-41d1-820a-68ed5b627c57/ rlnmp2in86qwysf*mgad0ayffcrzeixfoucpirzfuq4%21/b/dgyqo1jfdaaa&ek=1&kp=1&pt=0&bo= Hqknaaaaaaafajs%21&su=0194253761&sce=0-12-12&rf=2-9 "style=" WIDTH:487PX;HEIGHT:167PX; "height=" 167 " Width= "541" alt= "dgyqo1jfdaaa&ek=1&kp=1&pt=0&bo=hqknaaaaa"/>

The page opens as follows:
650) this.width=650; "Src=" http://b147.photo.store.qq.com/psb?/5d11cec8-02fc-41d1-820a-68ed5b627c57/ bx7opyq3vvsbkeh2x52n5jzeqktq8sjpovxwwelwhzg%21/b/dhopp1difwaa&ek=1&kp=1&pt=0&bo=. Ahraaaaaaafaas%21&su=058441329&sce=0-12-12&rf=2-9 "style=" WIDTH:490PX;HEIGHT:209PX; "height=" 209 " Width= "504" alt= "dhopp1difwaa&ek=1&kp=1&pt=0&bo=. Ahraaaaa "/>


3. Writing our CGI program
650) this.width=650; "Src=" http://b132.photo.store.qq.com/psb?/5d11cec8-02fc-41d1-820a-68ed5b627c57/ bo6txtu52vxxjzkt6obewlnh8mgg0xgrlwhtolzssnm%21/b/dcylr042kgaa&ek=1&kp=1&pt=0&bo= Wag7aaaaaaafafk%21&su=0241514913&sce=0-12-12&rf=2-9 "height=" 187 "width=" 448 "alt=" dCYlr042KgAA& Ek=1&kp=1&pt=0&bo=wag7aaaaa "/>
Compile the program to generate CGI files
650) this.width=650; "Src=" http://b148.photo.store.qq.com/psb?/5d11cec8-02fc-41d1-820a-68ed5b627c57/ hhrhl5qn.qrkh3yderodevi.dfqr3w5kp8ax2iwbdr4%21/b/dbtxrfjjdaaa&ek=1&kp=1&pt=0&bo= Oqjsaaaaaaafaeo%21&su=03353153&sce=0-12-12&rf=2-9 "height=" "width=" 569 "alt=" dBTXRFjjDAAA&ek=1 &kp=1&pt=0&bo=oqjsaaaaa "/>

4. Click the page button to see the effect:
650) this.width=650; "Src=" http://b145.photo.store.qq.com/psb?/5d11cec8-02fc-41d1-820a-68ed5b627c57/ 5i1hsho9eht4ktv3c.7vdignrhvn.zpba189esxkdvq%21/b/dlgce1aohqaa&ek=1&kp=1&pt=0&bo=. Wgcaaaaaaafaeu%21&su=086261777&sce=0-12-12&rf=2-9 "height=" 156 "width=" 507 "alt=" dLgce1aOHQAA&ek= 1&kp=1&pt=0&bo=.wgcaaaaa "/>

OK, a simple cig is finished, of course, you can call the environment variable to receive the data sent by webserver, do more complex operations.

C Language Programming CGI program (bottom)

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.