Multi-programming-language "cookbook", sample CGI code
Table of contents (after decoding relevant HTML FORM fields):
- Check whether a given parameter has been supplied, if so then (1) get the value of that parameter as a string, (2) display that value as text, and (3) check whether it's the correct string:
PHP
- Validate decimal integer in field within submitted HTML form:
PHP /
perl /
lisp /
c /
c++ /
java
(Correct format is: Optional whitespace,
optional sign, one or more consecutive digits, optional whitespace.
Try various of those options in the form. Also try putting garbage characters or extra whitespace in various places.)
Note: Except for fetching the HTML form contents itself, this code would work
equally well to validate user input via standard input. But by necessity,
all these demos run via the Web and take input via HTML forms (or
equivalently by manually-entered query strings that look like encoded
form contents).
- Set cookie, then later look for that cookie and fetch its value:
PHP
(Anybody who knows how to do all this per current practice
in any of the other languages, please
submit
code snippets that I can test myself and then include in sample demo here.)
- To do: Generate Latin-1 output
- To do: Generate UTF-8 output for alphabet-based languages
- To do: Generate UTF-8 output for Chinese characters
.
.
.
.
.
.
.
.
Check one key=val for correct value:
PHP
PHPCheck one key=val, PHP
(Warning: Case sensitive. All upper-case comes before any lower case!)
See source.
//INEDIT
.
.
.
.
.
.
.
.
Validating/parsing decimal-integer fields:
PHP /
perl /
lisp /
c /
c++ /
java
Decimal-integer fields, PHP
See source.
Decimal-integer fields, perl
See source.
Decimal-integer fields, common lisp
See source.
Decimal-integer fields, c
See source.
A re-write of that code, try this too:
See source.
Decimal-integer fields, c++
See source.
Decimal-integer fields, java
See source.
.
.
.
.
.
.
.
.
.
.
Setting cookie, then retrieving it later:
PHP /
perl /
lisp /
c /
c++ /
java
Set cookie, PHP
how to contact me
Copyright 2007 by Robert Elton Maas, all rights reserved