1 / 10

CGI 共通閘道介面 (Common Gateway Interface)

CGI 共通閘道介面 (Common Gateway Interface). 什麼是 CGI ?  為什麼需要 CGI ? 應用?  CGI 與 JAVA Script/VB Script 的差異?  CGI 的工具需求 ?  CGI 的環境設定注意事項  一個基本 CGI 程式實作 . 什麼是 CGI ?. CGI ( C ommon G ataway I nterface , 常被譯做「 共通閘道介面 」),是介於 WWW 伺服器與系統資源之間的一個介面。

walker
Download Presentation

CGI 共通閘道介面 (Common Gateway Interface)

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. CGI 共通閘道介面(Common Gateway Interface) • 什麼是CGI ?  • 為什麼需要CGI ? 應用?  • CGI 與 JAVA Script/VB Script的差異?  • CGI的工具需求 ?  • CGI的環境設定注意事項  • 一個基本CGI程式實作 

  2. 什麼是 CGI ? • CGI (Common Gataway Interface , 常被譯做「共通閘道介面」),是介於WWW伺服器與系統資源之間的一個介面。 • Common 的意義是「共通的」,表示CGI是一泛稱,而非特別指定某種程式語言或特殊介面。 • Gataway 提供了W3 伺服器一個存取其他外部資源或擴充能力的管道。 • Interface指的就是提供 W3 伺服器與外部資源之間的一個標準溝通介面。

  3. 3.CGI程式執行或存取適當資料 伺服器 Httpd 硬碟 檔案 資料庫 其他硬 體設備 2.伺服器傳回 WWW文件給瀏 覽器 CGI 程式 1.瀏覽器向伺 服器要求文件 4.CGI程式產生 一份新的WWW文件 2.伺服器依照需求 執行適當CGI程式 瀏覽器 Browser 伺服器 Httpd 5.伺服器傳回WWW 文件給瀏覽器 1.瀏覽器向伺服器 要求文件 瀏覽器 Browser 一般靜態文件瀏覽 動態CGI瀏覽流程

  4. 為什麼需要CGI ? 應用? • 一般的W3伺服器提供的是靜態W3文件。無法依照個別使用者需求,提供不同的文件內容。而CGI可以透過使用者的輸入或選擇,提供符合需求而動態產生的W3文件內容。 • 使用者動態需求  CGI的誕生  提供更便利、更符合個別需求的服務內容。 • 常見的CGI應用:搜尋引擎 : Kimo、PCHome、Yahoo!線上投票、聊天室、留言版、計數器、電子賀卡、網路銀行、線上購物、數位圖書館…等等。

  5. CGI與JAVA/VB Script的差異? • CGI是屬於伺服器端執行的機制,W3伺服器依照使用者的需求執行適當的CGI程式,動態產生新的W3文件。傳回使用者的W3文件內容中無法看到CGI程式的內容,使用者看到的只是一般的W3文件。由於CGI是在伺服器上執行,所以會增加伺服器的負擔,CGI程式效率不佳或使用到CGI的使用者過多時後造成服務效能下降。 • JAVA Script/Visual Basic Script存在伺服器傳回的W3文件中,當支援該Script的瀏覽器看到文件內容,會依照文件中的Script程式部分,在使用者端的電腦上執行Script的程式內容,產生動態效果、內容與適當的服務。JAVA/VB Script有先天上的限制,例如:無法直接存取伺服器端的外部資源、瀏覽器必須支援該Script語言…。 • ASP(Active Server Page, MS)與PHP…。

  6. CGI的工具需求? • 支援CGI的W3伺服器,例如: Apache、Samber…。 • 適合的程式語言,例如:C/C++、Perl、VB、Delphi…,並依照不同的程式語言準備適合的編譯器或直譯器。值得注意的是所選擇的W3伺服器是否有支援該程式語言或相關的擴充模組。 • 適合撰寫程式語言的編輯器,例如:vi、UltraEdit、記事本…。

  7. CGI的環境設定注意事項 • 以Apache Server (Linux RedHat )為例 :/etc/httpd/conf 目錄下的 httpd.conf、access.conf與srm.conf設定檔中相關CGI部分的設定。srm.conf ScriptAlias /cgi-bin/ /home/httpd/cgi-bin/ AddHandler cgi-script .cgi • 目錄環境存取權限的設定(owner/group/others : r/w/x):(1) cgi-bin 目錄屬性設為 711(2) CGI 程式檔案屬性設為 755(3) 欲寫入資料的檔案屬性設為 666

  8. 一個基本CGI程式實作 • 以 C 為例 :HelloWorld.c • 以 Perl 為例:HelloWorld.pl

  9. HelloWorld.c :#include <stdio.h>int main(int argc, char *argv[]){ printf(“Content-type:text/html\n\n”); printf(“<HEAD>\n”); printf(“<TITLE>Hello, World</TITLE>\n”); printf(“</HEAD>\n”); printf(“<BODY>\n”); printf(“<H1>Hello, World</H1>\n”); printf(“</BODY>\n”); return 0; }

  10. HelloWorld.pl :#!/usr/bin/perlprint “Content-type:text/html\n\n”;print “<HEAD>\n”;print “<TITLE>Hello, World</TITLE>\n”;print “</HEAD>\n”;print “<BODY>\n”;print “<H1>Hello, World</H1>\n”;print “</BODY>\n”;

More Related