TEXT   82
procedure main
Guest on 12th March 2023 09:12:09 AM


  1. procedure main(a)
  2.  
  3.     local i, cl, n, name_tbl
  4.  
  5.     cl := integer(getenv("CONTENT_LENGTH"))
  6.     name_tbl := table()
  7.  
  8.     #
  9.     # output a minimal header, terminated by two newlines
  10.     #
  11.     write("Content-type: text/html\x0A\x0A")
  12.  
  13.     #
  14.     # check that the request is correctly formatted; output
  15.     # error message if it's not
  16.     #
  17.     getenv("REQUEST_METHOD") == "POST" | {
  18.         writes("<P>error:  METHOD must = \"POST\"</P>")
  19.         exit(1)
  20.     }
  21.     getenv("CONTENT_TYPE") == "application/x-www-form-urlencoded" | {
  22.         writes("<P>error:  this script is for decoding form results only</P>")
  23.         exit(1)
  24.     }
  25.  
  26.     #
  27.     # enter name=value lines as key/value pairs in name_tbl
  28.     #
  29.     while line := makeline(&input, "&", cl) do {
  30.         line := unescape_url(map(line), "+", " ")
  31.         line ? {
  32.             n := tab(find("="))
  33.             move(1)
  34.             if not (/name_tbl[n] := tab(0)) then {
  35.                 writes("<P>error:  duplicate field name, ", n, "</P>")
  36.                 exit(1)
  37.             }
  38.         }
  39.     }

Raw Paste

Login or Register to edit or fork this paste. It's free.