Cgi for website development in C language and cgi for website development

Source: Internet
Author: User

Cgi for website development in C language and cgi for website development
Zookeeper

  1. Install Apach

  2. Configure ApacheRuntime

In the following process, click next

Configure CGI and release the configuration: AddHandler cgi-script. cgi

2. Add Option,

3. Write CGI Code as follows:

# Define_CRT_SECURE_NO_WARNINGS // cancel the security check

# Include <stdio. h>

# Include <stdlib. h>

# Include <string. h>

 

Voidmain ()

{

// If you want to display it in html, add the following two sentences:

Printf ("Content-type: text/html \ n ");

// Use the following method to query the environment variable string

Printf ("% s <br/>", getenv ("QUERY_STRING "));

CharszPost [256] = {0 };

// Obtain input

Gets (szPost );

// Obtain input

Printf ("% s <br/>", szPost );

// This statement moves the pointer to the equal sign position.

Char * p = szPost + 8;

Char * p1 = strchr (szPost ,"&");

* P1 = '\ 0 ';

 

Charcmd [256] = {0 };

// String ing

Sprintf (cmd, "% s> 1.txt", p );

System (cmd );

FILE * pf = fopen ("1.txt"," r ");

// Continue if it is not at the end of the file

While (! Feof (pf ))

{

Charch = fgetc (pf );

If (ch = '\ n ')

{

// Line feed

Printf ("<br/> ");

}

Else

{

// Print characters

Putchar (ch );

}

}

}

4. CLICK: local Windows Debugger

Open the file in file resource manager as follows:

The Debug directory is as follows:

5.change system.exebeibei to cgi-binin apachand system.exe to system. cgi.

6. Restart the Apache server and right-click Apach à Open Apache Monitor. The following page is displayed:

7. Compile the following html

<Html>

<Form method = "post" action = "http: // localhost/cgi-bin/system. cgi">

<P>

<Input type = "text" id = "command" name = "command"

Value = "tasklist" action = ""/>

</P>

<P>

<Input type = "submit" name = "submit" id = "submit" value = "submit"/>

</P>

</Form>

</Html>

 

It should be noted that, if an error still exists in the webpage, this may not be a program issue, but a cache issue. In this case, you should close the webpage and re-open it, this is the case.


I want to use C language for website development. I have heard that cgi can be used, but I don't know much about cgi. So I will introduce several small-and-white cgi books.

Prepare file printing "<br>" this string, very troublesome

What is the CGI program edited in C language?

CGI program design in C Language

1. CGI Overview
CGI (Public Gateway Interface) specifies the interface protocol standard for Web servers to call other executable programs (CGI program. The Web server calls the CGI program to implement interaction with the Web browser, that is, the CGI program receives and processes the information sent to the Web server by the Web browser, send the response to the Web server and Web browser. CGI programs generally process Form data on Web pages, query databases, and integrate with traditional application systems. CGI programs can be written in any programming language, such as Shell scripting language, Perl, Fortran, Pascal, and C language. However, CGI programs written in C language have the features of fast execution speed and high security (because C language programs are compiled and executed and cannot be modified.

The CGI interface standard consists of three parts: standard input, environment variable, and standard output.

1. Standard Input

CGI programs, like other executable programs, can get input information from the Web server through standard input (stdin), such as data in Form, this is the so-called POST method for passing data to CGI programs. This means that the CGI program can be executed in the command line status of the operating system to debug the CGI program. The POST method is a commonly used method. This article uses this method as an example to analyze the methods, processes, and techniques of CGI program design.

2. Environment Variables

The operating system provides many environment variables that define the execution environment of the program and the application can access them. The Web server and CGI interface also set some environment variables to pass some important parameters to the CGI program. The cgi get method also transmits the data in Form to the CGI program through the Environment Variable QUERY-STRING.

3. standard output

The CGI program transmits the output information to the Web server through the standard output (stdout. The information sent to the Web server can be in various formats, usually in plain text or HTML text, so that we can debug CGI programs in the command line status and get their output.

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.