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>