ap.rputs [[ 登录Apache的测试页面 ]] local session = require "cgilua.session" local globle = require"cgilua.globle" local cookies = require "cgilua.cookies" local msg = "" local sid local bLogin = false local users = {} if (cgi.authname) then users = globle.get(cgi.authname.."_users") or {} if(cgi["action"]=="登录") then u = cgi.username p = cgi.password sid = cookies.get("SID") local data = sid and session.get(sid) if(data and u==data.username and cgi.authname==data.authname) then msg = "用户"..data.username.."不需要重新登录" bLogin = true elseif (data and (u~=data.username or cgi.authname~=data.authname)) then -- 以其它用户的方式登录 session.delete(sid) end if (not bLogin) then if (users[cgi.username] == p) then msg = "用户"..cgi.username.."登录成功" bLogin = true sid = session.new(); options = {} options.path = "/" cookies.set("SID",sid, options) local data = session.get(sid) or {} data.username = cgi.username data.authname = cgi.authname session.set(sid,data) ap.print("登录成功") elseif (users[cgi.username]==nil) then msg = "用户"..cgi.username.." 不存在" else msg = "用户"..cgi.username.." 口令错误" end end elseif (cgi["action"]=="登出") then sid = cookies.get("SID") session.delete(sid) else sid = cookies.get("SID") local data = sid and session.get(sid) if(data) then msg = "用户"..data.username.."不需要重新登录" bLogin = true end end end ap.rputs [[ ]] ap.rputs( msg ) ap.rputs [[
]] if (not bLogin) then ap.rputs [[
帐号:
口令: ]] if (not cgi.authname) then ap.rputs [[
请选择认证服务器 ]] else ap.rputs [[ ]] end ap.rputs [[
]] else ap.rputs [[

]] end ap.rputs [[ ]]