- procedure main(a)
- local i, cl, n, name_tbl
- cl := integer(getenv("CONTENT_LENGTH"))
- name_tbl := table()
- #
- # output a minimal header, terminated by two newlines
- #
- write("Content-type: text/html\x0A\x0A")
- #
- # check that the request is correctly formatted; output
- # error message if it's not
- #
- getenv("REQUEST_METHOD") == "POST" | {
- writes("<P>error: METHOD must = \"POST\"</P>")
- exit(1)
- }
- getenv("CONTENT_TYPE") == "application/x-www-form-urlencoded" | {
- writes("<P>error: this script is for decoding form results only</P>")
- exit(1)
- }
- #
- # enter name=value lines as key/value pairs in name_tbl
- #
- while line := makeline(&input, "&", cl) do {
- line := unescape_url(map(line), "+", " ")
- line ? {
- n := tab(find("="))
- move(1)
- if not (/name_tbl[n] := tab(0)) then {
- writes("<P>error: duplicate field name, ", n, "</P>")
- exit(1)
- }
- }
- }
Raw Paste