怎样象大富翁一样,让登录一次就具可以访问所有页面了 (100分)

  • 主题发起人 bluebird
  • 开始时间
B

bluebird

Unregistered / Unconfirmed
GUEST, unregistred user!
特别请教YYSUN,以及各位大虾一个初级问题:
1.用CGI怎样做象大富翁一样,让登录一次就具可以访问所有页面了 ?
2.怎样判断何时离线,以便使重新登录
3.大富翁的问题列表多页面如何实现
4.有delphi示例或控件吗?
 
用cookie
请查关于cookie的问题!
 
象本论坛---登陆成功后,每次切换页面,都把登陆密码用明文cookie给用户。
然后判断不就成了?//转贴
 
A cookie test application:

The projectfile "CookieTest.dpr"
*******************************************************************
program CookieTest;

{$APPTYPE CONSOLE}

uses
HTTPApp,
CGIApp,
Unit1 in 'Unit1.pas' {WebModule1: TWebModule};

{$R *.RES}

begin
Application.Initialize;
Application.CreateForm(TWebModule1, WebModule1);
Application.Run;
end.
******************************************************************

A WebModule "Unit1.pas"
******************************************************************
unit Unit1;

interface

uses
Windows, Messages, SysUtils, Classes, HTTPApp;

type
TWebModule1 = class(TWebModule)
PageProducer1: TPageProducer;
procedure WebModule1WebActionItem1Action(Sender: TObject;
Request: TWebRequest; Response: TWebResponse; var Handled: Boolean);
procedure WebModule1WebActionItem2Action(Sender: TObject;
Request: TWebRequest; Response: TWebResponse; var Handled: Boolean);
procedure WebModule1WebActionItem3Action(Sender: TObject;
Request: TWebRequest; Response: TWebResponse; var Handled: Boolean);
private
{ Private declarations }
UserName, PassWord: String;
public
{ Public declarations }
end;

var
WebModule1: TWebModule1;

implementation

{$R *.DFM}

procedure TWebModule1.WebModule1WebActionItem1Action(Sender: TObject;
Request: TWebRequest; Response: TWebResponse; var Handled: Boolean);
begin
Response.Content := PageProducer1.Content;
end;

procedure TWebModule1.WebModule1WebActionItem2Action(Sender: TObject;
Request: TWebRequest; Response: TWebResponse; var Handled: Boolean);
var
UserName, PassWord: String;
ACookie: TCookie;
begin
UserName := Request.ContentFields.Values['UName'];
PassWord := Request.ContentFields.Values['PWord'];
ACookie := Response.Cookies.Add;
ACookie.Name := 'UName';
ACookie.Value := UserName;
ACookie := Response.Cookies.Add;
ACookie.Name := 'PWord';
ACookie.Value := PassWord;
Response.Content := 'User Name = ' + UserName + '<br>' + #13;
Response.Content := Response.Content + 'Password = ' + Password + '<br>' + #13;
Response.Content := Response.Content + '<a href="Check">Check Cookies</a>'
end;

procedure TWebModule1.WebModule1WebActionItem3Action(Sender: TObject;
Request: TWebRequest; Response: TWebResponse; var Handled: Boolean);
var
path : string;
begin
UserName := Request.CookieFields.Values['UName'];
PassWord := Request.CookieFields.Values['PWord'];
path := Request.PathInfo;
response.Content := 'Information from Cookie:<br>' + #13;
Response.Content := Response.Content + 'User Name = ' + UserName + '<br>' + #13;
Response.Content := Response.Content + 'Password = ' + Password + '<br>' + #13;
Response.Content := Response.Content + 'Path = ' + Path + '<br>' + #13;
Response.Content := Response.Content + '<a href="../CookieTest.exe">Retry</a>';
end;

end.

in this webmodule we have a Pageproducer(for user input) and three
actions

TPageProducer1.HTMLDoc:
--------------------------------------------
<html>
<head>
<title>Cookie Test</title>
</head>
<body>
<form method="POST" action="cookietest.exe/Logon">
<p>
用 户:<input type="text" name="UName" size="20"><br>
口 令:<input type="PassWord" name="PWord" size="20"><br>
<input type="submit" value="发 出" name="B1">
</p>
</form>
</body>
</html>
-------------------------------------------------------------

WebActionItem1 is default action for user input,
default := true; PathInfo := '';
WebActionItem2 is for handling user input and write cookies,
default := false; PathInfo := '/Logon';
WebActionItem3 is uset to check the cookies on client end,
default := false; PathInfo := '/Check';

 
那怎么样知道下线了
 
不可能,可以设置有效期的,这样用户关闭对话就需要再注册
 
那又如何设置有效期呢?
 
每次检查Request之前都要首先检查Cookie, 如果返回的Cookie值为空即表示用户下线了, 实质上就是用户把所有打开的浏览器窗口都关闭了.
 
COOKIE问题已经基本解决了,感谢各位
不过,还有个问题我不清楚,如何实现“修改”个人信息的CGI呢?
分数先分了
 
分了?
最简单是把用户名和密码直接POST给ASP
(也许是CGI/ISAPI)程序。不过安全我
不感说。问题也不想想象的那么糟糕,一
般IE/NETSCAPE都会把传输的数据自动加密
NT也提供类似的加密验证(MS说对IE是最安
全的,NETSCAPE也有验证)但不知道为什么
上海热线不支持验证,要我允许明文传输,
气死我了。

在服务器端不用我说了吧:
IF (OLDUSERNAME = USERINDB) AND (OLDPASSWORD = PASSINDB) THEN
BEGIN
USER_IN_DB := NEW_USER;
PASSWORD_IN_DB := NEW_PASSWORD;
RETURN SUCCESS_INFO;
END
ELSE
BEGIN
IF NESSARY THEN
LOG_FAILURE;
RETURN FAIL_INFO;
END;
 

Similar threads

S
回复
0
查看
3K
SUNSTONE的Delphi笔记
S
S
回复
0
查看
2K
SUNSTONE的Delphi笔记
S
D
回复
0
查看
941
DelphiTeacher的专栏
D
D
回复
0
查看
1K
DelphiTeacher的专栏
D
顶部