468,136 Members | 1,417 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,136 developers. It's quick & easy.

Login Logout question

Hiya, i made a asp page, and one of my divs (as a include) is as below. the problem is if the main page is resubmitted, i get logged out again?...

heres the code.. i think its on the value=true for the hidden textbox on the logout sub.. but how do i get round this? can i not change the value onclick?


<div id=Rightbody>
<!--<form id="RightBodyForm" name="RightbodyForm" method="post" action="Guestbook2.asp">-->
<%
Response.Expires = -1000 'Makes the browser not cache this page
Response.Buffer = True 'Buffers the content so our Response.Redirect will work

'If called displays the login form elements
'The login hidden field shows this is a login form
Sub ShowLogin
%>
<label>Username</label><br />
<input type="text" id=txtUsername name="txtUsername" /><br />
<label>Password</label><br />
<input type="password" id=txtPassword name="txtPassword" /><br />
<input type="hidden" name="login" value="true" />
<input type="button" value="Login" name="btnLogin" onClick="WithForm();" />
<%
End Sub

'Sub called to check whether or not user credentials are ok
'The logout hidden field shows this is a login form
Sub CheckLogin

dim strUsername
dim strPassword
dim strXMLLoginDetails

strUsername = Request.Form("txtUsername")
strPassword = Request.Form("txtPassword")
strXMLLoginDetails = "<HXML><Username>" & strUsername & "</Username><Password>" & strPassword & "</Password></HXML>"

'Response.Write Server.HTMLEncode(strXMLLoginDetails)
'Response.End

If strUsername <> "" OR strPassword <> "" then

dim objLoginNode
set objLoginDLL = createobject("Logindll.LoginClass")

dim GetLoginResult
GetLoginResult = objLoginDLL.LoginEntry(strXMLLoginDetails)

set objDOM = server.CreateObject("MSXML2.DOMDocument")
objDOM.LoadXML(GetLoginResult)



if objDOM.selectSingleNode("Response/RESULT").Text ="SUCCESS" then
Session("Loggedin")=objDOM.selectSingleNode("Respo nse/LOGIN/MembersName").Text
ShowLogout
Response.Redirect "Guestbook2.asp"
else
Response.Write "<span style=""color:red; padding:3px; background-color:#FEF0E2; border:1px solid red;"">The details you entered are incorrect</span>"
ShowLogin
end if
elseif len(Session("Loggedin"))>0 then
ShowLogout
else
showlogin
end if

End Sub

Sub ShowLogout
Response.Write "You are logged in:" & Session("Loggedin") & ""
%>
<input type="hidden" id=logout name="logout" value="true" />
<input type="submit" value="Log out" id="btnLogout" name="btnLogout" />
<%
End Sub

'Check to see if the login form has been submitted
If Request.Form("login") = "true" Then
'If so check the login details were correct
CheckLogin
'If not login, check to see if it is logout
ElseIf Request.Form("logout") = "true" Then
'Clear the session contents
'If this doesn't work just set them to empty or summat
Session.Contents.RemoveAll
Response.Write("You have been successfully logged out")
ShowLogin
'If username registered show logout
ElseIf len(Session("Loggedin"))>0 then
ShowLogout
'If first time show login
Else
ShowLogin
End If

%>
<!--</form>-->
</div>
Jan 24 '08 #1
1 2996
CroCrew
564 Expert 512MB
Why would someone come back to the login page if they are already logged in?

You might rethink this page and make it… Upon successful login redirect them to another page like a welcome page.

Also what are you using for a database?
Jan 25 '08 #2

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

1 post views Thread by MichaelR | last post: by
reply views Thread by ShailShin | last post: by
3 posts views Thread by Jennifer.Berube | last post: by
10 posts views Thread by DavidPr | last post: by
1 post views Thread by gcdp | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.