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("

error: METHOD must = \"POST\"

") exit(1) } getenv("CONTENT_TYPE") == "application/x-www-form-urlencoded" | { writes("

error: this script is for decoding form results only

") 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("

error: duplicate field name, ", n, "

") exit(1) } } }