Shell Script--Initial CGI

Source: Internet
Author: User

CGI according to the definition of Baidu Encyclopedia, as follows:

CGI is the specification of external programs when the Web server is running, and programs written by CGI can extend server functionality. CGI applications can interact with the browser, and data can be obtained from the database server by communicating with external data sources such as database servers through the database API. When formatted as an HTML document, it is sent to the browser, or the data obtained from the browser can be placed in the database. CGI is supported on almost all servers, and CGI can be written in any language, including popular C, C + +, VB, and Delphi. CGI is divided into two types of standard CGI and indirect CGI. Standard CGI uses command line arguments or environment variables to represent detailed server requests, and the server communicates with the browser using standard input and output methods.    Indirect CGI, also known as buffered CGI, inserts a buffer between the CGI program and the CGI interface, and the buffer program communicates with the CGI interface using standard input and output.  The above paragraph of the first contact with CGI, may not understand what the meaning, the following example is easy to understand. In Apache, for example, there is a folder in the root directory for/cgi-bin, which searches for CGI in configuration file httpd.conf
<ifmodule alias_module>    scriptalias/cgi-bin/"/usr/local/apache/cgi-bin/" </ifmodule><ifmodule cgid_module>    #Scriptsock cgisock</ifmodule><directory "/usr/local/apache/cgi-bin" >    allowoverride all    Options None    Require all granted</directory>

Enter the Cgi-bin directory and create a file with a file name of index.cgi and a. cgi file name extension, which is the same as the php file extension. php.

The contents of index.cgi are as follows:

  

#!/bin/bash#index.cgiecho "Content-type:text/html;charset=utf-8" Echoecho "Hello World"

Then visit localhost/cgi-bin/index.cgi in the browser and you will see the results as follows:

Then change the contents of the index.cgi:

#!/bin/bash#index.cgiecho "Content-type:text/html;charset=utf-8" echomysql= "Mysql-uroot-proot" sql= "show databases "$mysql-E" $sql "

The browser runs as follows:

In fact, from the above example, you will come to the conclusion that CGI is similar to PHP, except that PHP files use PHP syntax, the use of the CGI shell command, but can be run through the browser script, to obtain results.

Shell Script--Initial CGI

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.