test_session.lua 1005 B

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. cgilua.enablesession ()
  2. function pt (tab)
  3. for i, v in pairs (tab) do
  4. local vv = v
  5. if type(v) == "table" then
  6. vv = ""
  7. for _i, _v in pairs (v) do
  8. vv = vv..string.format ("%s = %q, ", _i, _v)
  9. end
  10. vv = '{'..vv..'}'
  11. end
  12. cgilua.put (string.format ("%s = %s<br>\n", tostring (i), tostring (vv)))
  13. end
  14. end
  15. if cgi.field then
  16. if not cgilua.session.data.field then
  17. cgilua.session.data.field = {}
  18. end
  19. table.insert (cgilua.session.data.field, cgi.field)
  20. end
  21. cgilua.htmlheader()
  22. if cgilua.session then
  23. cgilua.put "cgi = {<br>\n"
  24. pt (cgi)
  25. cgilua.put "}<br>\n"
  26. cgilua.put "cgilua.session.data = {<br>\n"
  27. pt (cgilua.session.data)
  28. cgilua.put "}<br>\n"
  29. cgilua.put [[<form action="]]
  30. cgilua.put (cgilua.mkurlpath"test_session.lua")
  31. cgilua.put [[" method="POST">
  32. field: <input type="text" name="field" value="]]
  33. cgilua.put (cgi.field or "")
  34. cgilua.put [["><br>
  35. <input type="submit"><br>
  36. </form>]]
  37. else
  38. cgilua.put "Sessions library is not available or not well configured"
  39. end