Sign in Join
Wiki copytemporary

CGI Web Programming/zh CN: what changed

Revision 0 to 1. Removed lines have a minus sign; added lines have a plus sign.

Title: CGI Web Programming/zh CN

OldNewLine
1+我刚刚开始从英文页面翻译这篇文章。我会尽力快速完成它。
2+
3+This is the start of a tutorial about cgi web programming. Everyone is invited to contribute.
4+
5+这是CGI教程的小小开始,希望所有人做出贡献。
6+
7+## 关于 CGI
8+
9+[**CGI**(通用通道界面)](http://en.wikipedia.org/wiki/Common_Gateway_Interface) 并不复杂:
10+
11+有两台计算机——客户端和服务器:
12+
13+- 服务器存储了要访问的文件(网页、图象和CGI)。
14+- 客户端通常使用网络浏览器请求服务器上的文档。
15+
16+只有你的服务器支持,你才能使用CGI。
17+
18+After hosted, CGI can now be used normally as: **http://www.yourserver.com\[.xx\]/yourlogin/cgi-bin/cginame.exe**
19+
20+**Notes:**
21+
22+- The CGI file don't need has the **.exe** extension.
23+- The CGI should be, obviously, compiled for the platform of the computer server (Linux, Windows...)
24+
25+## 关于 FreePascal CGI 以及如何测试你的CGI
26+
27+Free Pascal 的CGI程序是普通的可执行程序。
28+
29+请注意,Free Pascal CGI不是解释执行的,而是编译执行的。
30+
31+要测试你的CGI你必须在你的计算机上架设服务器,并且支持CGI.
32+
33+我推荐一种优良的[HTTP服务器](http://en.wikipedia.org/wiki/HTTP_Server) ——[Apache](http://en.wikipedia.org/wiki/Apache_HTTP_Server) 。 支持多种操作系统平台。 Another **HTTP Server** is [Xitami](http://en.wikipedia.org/wiki/Xitami) that supports CGIs in perl CGI and 16bits (but **Xitami** is very archaic).
34+
35+## 一个很简单的样例
36+
37+Here is an example of a minimal CGI program to demonstrate...
38+
39+1. Setting a cookie
40+2. Outputting the content-type (ie make it put out legal text for HTTP)
41+3. Reading Cookies
42+4. Reading form data via GET
43+5. Reading form data via POST
44+
45+``` pascal
46+program mini;
47+
48+uses dos;
49+
50+var
51+ a:string;
52+ c:char;
53+begin
54+ //set a cookie (must come before content-type line below)
55+ //don't forget to change the expires date
56+writeln('Set-cookie:widget=value; path=/; expires= Mon, 21-Mar-2005 18:37:00 GMT');
57+
58+ //output legal http page
59+ writeln('Content-Type:text/html',#10#13);
60+
61+ //demonstrate get cookies
62+ a:= GetEnv('HTTP_COOKIE');
63+ writeln('cookies:',a);
64+
65+ //demonstrate GET result
66+ a:='';
67+ a:= GetEnv('QUERY_STRING');
68+ writeln('GET: ',a);
69+
70+ //demonstrate POST result
71+ a:='';
72+ while not eof(input) do
73+ begin
74+ read(c);
75+ a:= a+c;
76+ end;
77+ writeln('POST: ',a);
78+end.
79+```
80+
81+## A simple hitcounter
82+
83+The application **hitcounter** presents a simple hitcounter for your website. It is possible to enter blocklists in a configfile so robots and perhaps your own computer are excluded from the statistics. There are still a lot of improvements possible ofcourse like setting a cookie so you get only one hit per session, but it gives a good introduction into CGI programming. If you use the code and modify it, please send me a patch so I can update it.
84+
85+You can find the code here: [1](http://modelbuilder.svn.sourceforge.net/viewvc/modelbuilder/html/cgi/)
86+
87+## Existing CGI Frameworks
88+
89+There are existing CGI units and frameworks that make working with CGI trivial (and allow one to set cookies, sessions, retrieve POST and GET). See [Powtils](http://z505.com/powtils/idx.shtml)
90+
91+There is also a CGIModule for lazarus, and a few CGI and HTML units in the freepascal FCL.
92+
93+Another CGI and FastCGI framework for FreePascal/Delphi is [ExtPascal](http://extpascal.googlecode.com) an Ext JS wrapper.
94+
95+---
96+*From the Free Pascal wiki, page "CGI Web Programming/zh CN", as it stood on 2020-02-10 after a change by Trev, out of the wiki's dump of 2024-05-26. Copyright stays with the author who wrote it, according to the old wiki's [[Licensing]] page. If you have concerns about this material, [message the admin](/wiki-contact).*

Back to history