//------------------------------------------------------------------------------ // Uint: 例子/会话 //------------------------------------------------------------------------------ unit session; interface uses System.SysUtils, System.IOUtils, System.Classes, FireHttp.Utils, FireHttp.Types, FireHttp.Classes, FireHttp.HTML, FireHttp.Path, FireHttp.Log, FireHttp.Config; type example_session = class(THTMLHandler) public const __PathInfo = '/session'; const __Description = ''; protected procedure Execute; override; procedure Cleanup; override; public constructor Create(AThread: TWorkerThread); override; destructor Destroy; override; end; implementation { example_session } procedure example_session.Cleanup; begin inherited; end; constructor example_session.Create(AThread: TWorkerThread); begin inherited Create(AThread); {$region '设置处理者'} MultiPathInfo.Add(__PathInfo); Description := __Description; {$endregion} end; destructor example_session.Destroy; begin inherited; end; procedure example_session.Execute; var ul, li, br, a: THTMLElement; begin inherited; SessionStart; Document.Title.Text := 'Session'; if Request.Method = THttpMethod._GET then begin {$region 'Logout'} if Request.QueryFields.GetAsString('logout') = '1' then begin Session['username'] := ''; Session['password'] := ''; Response.Redirect('session'); Exit; end; {$endregion} if Session['username'] = '' then begin {$region 'Not logged in'} Document.Body.HTML := '
'; {$endregion} end else begin {$region 'Logged in'} //Session Info ul := Document.CreateElement_UL(Document.Body); li := Document.CreateElement_LI(ul); li.Text := 'SessionId=' + SessionId; li := Document.CreateElement_LI(ul); li.Text := 'Session[''username'']=' + Session['username']; li := Document.CreateElement_LI(ul); li.Text := 'Session[''password'']=' + Session['password']; //