Link to home
Start Free TrialLog in
Avatar of tikkanen
tikkanen

asked on

Log out in asp

Hello,

Now, I have logging page (thanks to B_Dorsey), all i need is somekind of session management and logging out features. User visit different pages and he has own session id. Session expires then when he close Internet Expolerer. here is my code:

<%@ Language = "VBScript" %>
<% Option Explicit %>
<%

Dim cnnLogin
Dim rstLogin
Dim strUsername, strPassword
Dim strSQL
Dim dsn
Dim sSQL
%>
<html>
<head><title>Asp -kirjautumissivu</title>
<link href="tyylit.css" rel="stylesheet" type="text/css">
</head>
<body bgcolor="#FFFFFF">
<%
If Request.Form("action") <> "validate_login" Then
      %>
      <form action="login2.asp" method="post">
      <input type="hidden" name="action" value="validate_login" />
      <table border="0">
            <tr>
                  <td align="right"><p>Käyttäjätunnus:</p></td>
                  <td><input type="text" name="login" /></td>
            </tr>
            <tr>
                  <td align="right"><p>Salasana:</p></td>
                  <td><input type="password" name="password" /></td>
            </tr>
            <tr>
                  <td align="right"></TD>
                  <td><input type="submit" VALUE="Lähetä" /></td>
            </tr>
      </table>
      </form>
      <%
Else
      strSQL = "SELECT * FROM users " _
            & "WHERE LoginName ='" & Replace(Request.Form("login"), "'", "''") & "' " _
            & "AND Password ='" & Replace(Request.Form("password"), "'", "''") & "';"

'määrittele  tietokanta ja sen sijainti
'
dsn="dsn=iWayDB;Uid=sa;Pwd=;"
'Luo ADO -yhteys
Set cnnLogin = Server.CreateObject("ADODB.Connection")

'avaa  yhteys tietokantaan
cnnLogin.Open dsn

'Avaa tietue ja suorita tietokantakysely

      Set rstLogin = cnnLogin.Execute(strSQL)

      If Not rstLogin.EOF Then
            %>
            <p>
            <strong>Olet kirjautunut sisään...</strong>
            </p>
            <%
      Else
            %>
            <p>
            <font size="4" face="arial,helvetica"><strong>
            Kirjautuminen epäonnistui..
            </strong></font>
            </p>
            <p>
            <a href="login2.asp">Yritä uudestaan</a>
            </p>
            <%
            'Response.End
      End If

      ' Siivoa
      rstLogin.Close
      Set rstLogin = Nothing
      cnnLogin.Close
      Set cnnLogin = Nothing
End If
%>
</body>
</html>
ASKER CERTIFIED SOLUTION
Avatar of third
third
Flag of Philippines image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of tikkanen
tikkanen

ASKER

We are close, but now, when i have click logout -link, I can still go my restricted pages usin browser 'back' button. How  can I disapled that?

Here is my sample codes:

This is my new login page

<%@ Language = "VBScript" %>
<% Option Explicit %>
<%
'sivuilta http://www.asp101.com/samples/login.asp

Dim cnnLogin
Dim rstLogin
Dim strUsername, strPassword
Dim strSQL
Dim dsn
Dim sSQL
%>
<html>
<head><title>Asp -kirjautumissivu</title>
<link href="tyylit.css" rel="stylesheet" type="text/css">
</head>
<body bgcolor="#FFFFFF">
<%
If Request.Form("action") <> "validate_login" Then
      %>
      <form action="login2.asp" method="post">
      <input type="hidden" name="action" value="validate_login" />
      <table border="0">
            <tr>
                  <td align="right"><p>Käyttäjätunnus:</p></td>
                  <td><input type="text" name="login" /></td>
            </tr>
            <tr>
                  <td align="right"><p>Salasana:</p></td>
                  <td><input type="password" name="password" /></td>
            </tr>
            <tr>
                  <td align="right"></TD>
                  <td><input type="submit" VALUE="Lähetä" /></td>
            </tr>
      </table>
      </form>
      <%
Else
      strSQL = "SELECT * FROM users " _
            & "WHERE LoginName ='" & Replace(Request.Form("login"), "'", "''") & "' " _
            & "AND Password ='" & Replace(Request.Form("password"), "'", "''") & "';"

'määrittele  tietokanta ja sen sijainti
'
dsn="dsn=iWayDB;Uid=sa;Pwd=;"
'Luo ADO -yhteys
Set cnnLogin = Server.CreateObject("ADODB.Connection")

'avaa  yhteys tietokantaan
cnnLogin.Open dsn

'Avaa tietue ja suorita tietokantakysely

      Set rstLogin = cnnLogin.Execute(strSQL)

      If Not rstLogin.EOF Then
      Session("istunto")=True
      Response.Redirect("ok.asp")
            %>
            <p>
            <strong>Okstrong>
            </p>
            <%
      Else
            %>
            <p>
            <font size="4" face="arial,helvetica"><strong>
            Not ok
            </strong></font>
            </p>
            <p>
            <a href="login2.asp">Try again</a>
            </p>
            <%
            'Response.End
      End If

      ' Siivoa
      rstLogin.Close
      Set rstLogin = Nothing
      cnnLogin.Close
      Set cnnLogin = Nothing
End If
%>
</body>
</html>
============================================================
ok.asp

<%
If Session("istunto") <>True Then
response.redirect "login2.asp"
End If
%>

<html>
<head>
<title>1</title>
<link href="tyylit.css" rel="stylesheet" type="text/css">
</head>
<body>
ok<br><br>
Session log out test<br>

<br><br><br>
<a href="ulos.asp">logout</a>Kirjaudu ulos</>
</body>
</html>
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial