Foxtable(狐表)用户栏目专家坐堂 → [求助]DeleteCookie 删除后还可以通过网页的后退按钮返回登录的状态


  共有2686人关注过本帖树形打印复制链接

主题:[求助]DeleteCookie 删除后还可以通过网页的后退按钮返回登录的状态

帅哥哟,离线,有人找我吗?
有点蓝
  1楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:超级版主 帖子:106242 积分:540333 威望:0 精华:9 注册:2015/6/24 9:21:00
  发帖心情 Post By:2017/4/21 10:23:00 [显示全部帖子]

是会返回之前的页面,浏览器是直接取缓存的,没有到服务器刷新,所以不会有校验。一旦点击页面触发后台就会跳转到登录页面的
[此贴子已经被作者于2017/4/21 10:26:56编辑过]

 回到顶部
帅哥哟,离线,有人找我吗?
有点蓝
  2楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:超级版主 帖子:106242 积分:540333 威望:0 精华:9 注册:2015/6/24 9:21:00
  发帖心情 Post By:2017/4/21 14:35:00 [显示全部帖子]

15楼的项目我测验也没有问题,浏览器和手机都可以

或者试试这种用法

在有退出按钮的页面设置以下代码,强制页面刷新,然后就会重新验证登录信息

        if (window.name != "页面名称") {
            location.reload();
            window.name = "页面名称";
        } 
        else {
            window.name = "";
        } 

例如:
cookieremovhistory.js:

        if (window.name != "default") {
            location.reload();
            window.name = "default";
        } 
        else {
            window.name = "";
        } 

HttpRequest:

Dim wb As New weui
'身份验证
Dim Verified As Boolean '用于标记用户是否通过了身份验证
Dim UserName As String = e.Cookies("username") '从cookie中获取用户名
Dim Password As String = e.Cookies("password") '从cookie中获取用户密码
If e.Path = "logon.htm" '如果是通过登录页面访问,从PostValues即可中提取用户名和密码
    If e.PostValues.ContainsKey("username") AndAlso e.PostValues.ContainsKey("password")  Then
        UserName = e.PostValues("username")
        Password = e.PostValues("password")
    End If
End If
'msgbox(UserName)
If UserName = "张三" AndAlso Password = "888" Then  '实际使用的时候,请改为从数据库读取用户名和密码进行比较
    Verified  = True
ElseIf Username = "李四" AndAlso Password="999" Then
    Verified  = True
End If
'msgbox(Verified  )
If Verified AndAlso e.Path = "logon.htm"  Then '如果用户访问的是登录页,且身份验证成功
    wb.AppendCookie("username",UserName) '将用户名和密码写入cookie
    wb.AppendCookie("password",Password)
    wb.InsertHTML("<meta http-equiv='Refresh' c>") '直接跳转到首页
    e.WriteString(wb.Build) '生成网页
    Return '必须的
ElseIf Verified = False AndAlso e.Path <> "logon.htm" Then '如果用户身份验证失败,且访问的不是登录页面
wb.InsertHTML("<meta http-equiv='Refresh' c>") '直接跳转到首页
    e.WriteString(wb.Build) '生成网页
    Return '必须的
End If

'开始生成网页
Select Case e.path
    Case "logon.htm" '登录页面
        wb.AddPageTitle("","pageheader","销售系统","")
        If e.PostValues.ContainsKey("username") AndAlso e.PostValues.ContainsKey("password")  Then '判断是否是验证失败后的重新登录
            wb.AddTopTips("","toptip1","用户名或密码错误!").msec = 2000 '如果用户通过登录按钮访问,则给用户一个2秒的提示.
        End If
        wb.AddForm("","form1","logon.htm")
        With wb.AddInputGroup("form1","ipg1")
            .AddInput("username","户名","text")
            .AddInput("password","密码","password")
        End With
        With wb.AddButtonGroup("form1","btg1",True)
            .Add("btn1", "登录", "submit")
        End With
    Case "exit.htm" '退出登录
        wb.DeleteCookie("username") '清除cookie中原来的用户名和密码
        wb.DeleteCookie("password")
        wb.InsertHTML("<meta http-equiv='Refresh' c>") '那么直接跳转到登录页面
    Case "", "default.htm" '首页
        wb.AddPageTitle("","pageheader","")
        With wb.AddGrid("","g1")
            With .Add("c1","增加订单", "./images/button.png")
                .Attribute = ""
            End With
            .Add("c12","退出", "./images/exit.png", "exit.htm") '退出登录
            wb.AppendHTML("<script src='./lib/cookieremovhistory.js'></script>") '引入脚本文件
        End With
End Select
e.WriteString(wb.Build) '生成网页
 下载信息  [文件大小:   下载次数: ]
图片点击可在新窗口打开查看点击浏览该文件:管理项目18.foxdb


[此贴子已经被作者于2017/4/21 14:34:51编辑过]

 回到顶部