Difference between revisions of "CGI Web Programming/fr"

From Lazarus wiki
Jump to navigationJump to search
Line 7: Line 7:
  
 
Nous avons deux ordinateurs :
 
Nous avons deux ordinateurs :
* Ordinateur serveur - Cet ordinateur stockera les fichiers hébergés (pages web, images et CGIs);
+
* Ordinateur serveur - Cet ordinateur stockera les fichiers hébergés (pages web, images et CGI);
 
* Ordinateur client - En général, cet ordinateur utilise un navigateur pour demander les fichiers hébergés sur l'ordinateur serveur.
 
* Ordinateur client - En général, cet ordinateur utilise un navigateur pour demander les fichiers hébergés sur l'ordinateur serveur.
  
Vous pouvez employer les CGIs seulement si votre serveur d'hébergement supporte les CGI.
+
Vous pouvez employer les CGI seulement si votre serveur d'hébergement supporte les CGI.
 
Après avoir hébergé vos fichiers, le CGI est généralement utilisé ainsi :
 
Après avoir hébergé vos fichiers, le CGI est généralement utilisé ainsi :
 
'''<nowiki>http://www.yourserver.com[.xx]/yourlogin/cgi-bin/cginame.exe</nowiki>'''
 
'''<nowiki>http://www.yourserver.com[.xx]/yourlogin/cgi-bin/cginame.exe</nowiki>'''

Revision as of 10:55, 6 May 2012

English (en) español (es) français (fr) Bahasa Indonesia (id) русский (ru) 中文(中国大陆)‎ (zh_CN)

Ceci est le début d'un tutorial relatif à la programmation cgi web. Tout le monde est invité à contribuer.

A propos de CGI

CGI (Common Gateway Interface) fonctionne simplement comme ceci :

Nous avons deux ordinateurs :

  • Ordinateur serveur - Cet ordinateur stockera les fichiers hébergés (pages web, images et CGI);
  • Ordinateur client - En général, cet ordinateur utilise un navigateur pour demander les fichiers hébergés sur l'ordinateur serveur.

Vous pouvez employer les CGI seulement si votre serveur d'hébergement supporte les CGI. Après avoir hébergé vos fichiers, le CGI est généralement utilisé ainsi : http://www.yourserver.com[.xx]/yourlogin/cgi-bin/cginame.exe

Notes:

  • Le fichier CGI n'a pas besoin de l'extension .exe.
  • Le CGI devra être (évidemment) compilé pour la plateforme de l'ordinateur serveur (Linux, Windows ...)

About FreePascal CGI and how you can test your CGIs

A CGI Free Pascal is a normal executable program, as any program in your computer. Unlike the CGIs in Perl, Free Pascal CGI isn't interpreted. It's a independent executable program.

To test a CGI, you must have installed on your PC a HTTP Server with support for CGI. A good, and recommended HTTP Server is Apache, available both for Windows and Linux. Another HTTP Server is Xitami that supports CGIs in perl CGI and 16bits (but Xitami is very archaic).

A very basic example

Here is an example of a minimal CGI program to demonstrate...

  1. Setting a cookie
  2. Outputting the content-type (ie make it put out legal text for HTTP)
  3. Reading Cookies
  4. Reading form data via GET
  5. Reading form data via POST
program mini;

uses dos;

var
  a:string;
  c:char;
begin
  // set a cookie (must come before content-type line below)
  // don't forget to change the expires date
writeln('Set-cookie:widget=value; path=/; expires= Mon, 21-Mar-2005  18:37:00 GMT');

  // output legal http page
  writeln('Content-Type:text/html',#10#13);

  // demonstrate get cookies
  a:= GetEnv('HTTP_COOKIE');
  writeln('cookies:',a);
  
  // demonstrate GET result
  a:='';
  a:= GetEnv('QUERY_STRING');
  writeln('GET: ',a);
	
  // demonstrate POST result 
  a:='';
  while not eof(input) do
  begin
     read(c);
     a:= a+c;
  end;	 
  writeln('POST: ',a);
end.

A simple hitcounter

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.

You can find the code here: [1]


Existing CGI Frameworks

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

There is also a CGIModule for Lazarus, and a few CGI and HTML units in the freepascal FCL.

Another CGI and FastCGI framework for FreePascal/Delphi is ExtPascal an Ext JS wrapper.