以文本方式查看主题

-  Foxtable(狐表)  (http://www.foxtable.com/bbs/index.asp)
--  专家坐堂  (http://www.foxtable.com/bbs/list.asp?boardid=2)
----  [求助]DeleteCookie 删除后还可以通过网页的后退按钮返回登录的状态  (http://www.foxtable.com/bbs/dispbbs.asp?boardid=2&id=99543)

--  作者:blsu33
--  发布时间:2017/4/21 9:49:00
--  [求助]DeleteCookie 删除后还可以通过网页的后退按钮返回登录的状态
老师,
   帮助文档,操作过程中,发现退出理论是清除cookie中原来的用户名和密码,需要重新登录

        wb.DeleteCookie("username") \'清除cookie中原来的用户名和密码
        wb.DeleteCookie("password")
        wb.InsertHTML("<meta http-equiv=\'Refresh\' c>") \'那么直接跳转到登录页面
为何还可以通过网页的前进后退按钮返回已经登录的状态(不用输入密码)?

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

--  作者:有点色
--  发布时间:2017/4/21 10:30:00
--  

测试了一下,你可以用js防止后退

 

        //防止页面后退
        history.pushState(null, null, document.URL);
        window.addEventListener(\'popstate\', function () {
            history.pushState(null, null, document.URL);
        });

 

你在登陆页面那里引入此js代码即可。


--  作者:blsu33
--  发布时间:2017/4/21 10:36:00
--  
 老师,
   为何 这样不行呢?
 Case "", "default.htm" \'首页
        \'重新验证开始
        If e.PostValues.ContainsKey("username") AndAlso e.PostValues.ContainsKey("password")  Then
            UserName = e.PostValues("username")
            Password = e.PostValues("password")
        End If
        If UserName="" OrElse Password="" Then \'如果用户身份验证失败,应返回到登录页面
            wb.InsertHTML("<meta http-equiv=\'Refresh\' c>") \'那么直接跳转到登录页面
            e.WriteString(wb.Build) \'生成网页
            Return \'必须的
        End If
        \'重新验证结束
        wb.AddPageTitle("","pageheader","")
        With wb.AddGrid("","g1")
            With .Add("c1","增加订单", "./images/button.png")
                .Attribute = ""
            End With


--  作者:blsu33
--  发布时间:2017/4/21 10:41:00
--  
 理论上 上次退出了 UserName Password 已经为空了 ,如果进入default.htm ,没有信息,应该跳转到登陆界面
--  作者:blsu33
--  发布时间:2017/4/21 10:51:00
--  
老师 ,
是否是这个情况
虽然服务器端删除了Cookie,但是浏览器按钮的后退,缓存的是浏览器的端的Cookie对应的界面?


--  作者:有点色
--  发布时间:2017/4/21 11:03:00
--  
以下是引用blsu33在2017/4/21 10:41:00的发言:
 理论上 上次退出了 UserName Password 已经为空了 ,如果进入default.htm ,没有信息,应该跳转到登陆界面

 

后退的时候,不会访问服务器,所以无法触发代码。

 

你看3楼的方法,把js代码引入到你的登录页面去 http://www.foxtable.com/mobilehelp/scr/0061.htm

 


--  作者:blsu33
--  发布时间:2017/4/21 11:05:00
--  
 老师,
按照3楼 代码怎么加?

我已经建立了一个文本文件cookieremovhistory
内容
 //防止页面后退
        history.pushState(null, null, document.URL);
        window.addEventListener(\'popstate\', function () {
            history.pushState(null, null, document.URL);
        });

服务器端,代码填写在哪里,如何引入js文件代码?


\'通用事件头,用于发送已经存在的常见文件
Dim fl As String = "G:\\移动开发\\网页结构和表结构的关联\\" & e.path
If filesys.FileExists(fl)
    Dim idx As Integer = fl.LastIndexOf(".")
    Dim ext As String  = fl.SubString(idx)
    Select Case ext
        Case ".jpg",".gif",".png",".bmp",".wmf",".js",".css" ,".html",".htm",".zip",".rar"
            e.WriteFile(fl)
            Return \'这里必须返回
    End Select
End If
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
If UserName = "张三" AndAlso Password = "888" Then  \'实际使用的时候,请改为从数据库读取用户名和密码进行比较
    Verified  = True
ElseIf Username = "李四" AndAlso Password="999" Then
    Verified  = True
End If
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
                  End With
End Select
e.WriteString(wb.Build) \'生成网页


--  作者:有点色
--  发布时间:2017/4/21 11:16:00
--  

做一个js文件,引入,参考

 

http://www.foxtable.com/mobilehelp/scr/0061.htm

 


--  作者:blsu33
--  发布时间:2017/4/21 11:32:00
--  
老师 是这样吗?


 \'通用事件头,用于发送已经存在的常见文件
Dim fl As String = "G:\\移动开发\\网页结构和表结构的关联\\" & e.path
If filesys.FileExists(fl)
    Dim idx As Integer = fl.LastIndexOf(".")
    Dim ext As String  = fl.SubString(idx)
    Select Case ext
        Case ".jpg",".gif",".png",".bmp",".wmf",".js",".css" ,".html",".htm",".zip",".rar"
            e.WriteFile(fl)
            Return \'这里必须返回
    End Select
End If
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
If UserName = "张三" AndAlso Password = "888" Then  \'实际使用的时候,请改为从数据库读取用户名和密码进行比较
    Verified  = True
ElseIf Username = "李四" AndAlso Password="999" Then
    Verified  = True
End If
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
        End With
End Select
wb.AppendHTML("<script src=\'./lib/cookieremovhistory.js\'></script>") \'引入脚本文件
e.WriteString(wb.Build) \'生成网页