her er scriptet der på server1 checker om bruger er medlem + skriver en cookie fra server 1 hvis han er
Remote.login.asp
<%
Dim strSQL ' Stuctured Query Language
Dim objConn ' Database Connection
Dim objRs ' Recordset
Dim strLoginName ' Name user logs on with
Dim strLoginPassword ' Password to login with
Dim lngMemberID ' MemberID assigned to account
' Ensure page results do not remain in cache
Response.Expires = 0
Response.ExpiresAbsolute = Now()
' Grab querystring data
strLoginName = Request.Form("LoginName")
strLoginPassword = Request.Form("LoginPassword")
' Open database connection
Set objConn = Server.CreateObject("ADODB.Connection")
Set objRs = Server.CreateObject("ADODB.Recordset")
objConn.Open "DRIVER=Microsoft Access Driver (*.mdb);DBQ=" & Server.MapPath("Members.mdb")
' Search for Member Account
strSQL = "SELECT MemberID FROM Members WHERE LoginName = '" & strLoginName & "' AND LoginPassword = '" & strLoginPassword & "'"
Set objRs = objConn.Execute(strSQL)
' Notify viewer/server of results
If objRs.EOF Then
Response.Write("Login Failed")
Else
lngMemberID = objRs(0)
Response.Write(lngMemberID)
Response.Cookies("MinServerUser").Path = "/"
Response.Cookies("MinServerUser")("Name") = strLoginName
Response.Cookies("MinServerUser")("Pword") = strLoginPassword
' HACK: Errors occur if result is a single number
Response.Write(".")
End If
Response.Write "<HR>QueryString: " & Request.QueryString & "<HR>"
Response.Write "<HR>Form: " & Request.Form & "<HR>"
' Garbage Collection
Set objRs = Nothing
objConn.Close
Set objConn = Nothing
Response.End
%>
her er funktionen der skal ligge på server 2 i filen...
functions.asp, der ligger på minserver2.dk:
<%
function checkLogin()
Dim strSQL ' Structured Query Language
Dim strLoginName ' Name user logs on with
Dim strLoginPassword ' Password to login with
Dim lngMemberID ' MemberID assigned to user account
Dim objSpider ' Spider to request HTML page that logs user into system
Dim strResponseText ' Response returned from remote server
Dim strQueryString ' QueryString
' URL to page that allows other servers to log users against centralized
' database. (This may need to be changed)
Const strURL = "
http://minserver1.dk/Remote.Login.asp"' Grab posted form data
strLoginName = Request.Form("LoginName")
strLoginPassword = Request.Form("LoginPassword")
strQueryString = _
"LoginName=" & Server.URLEncode(strLoginName) & _
"&LoginPassword=" & Server.URLEncode(strLoginPassword)
' Log user into remote location and get results
Set objSpider = Server.CreateObject("Microsoft.XMLHTTP")
' other versions ...
' MSXML2.XMLHTTP.3.0, MSXML2.ServerXMLHTTP, Microsoft.XMLHTTP
With objSpider
Call .Open("POST", strURL, False, "", "")
Call .setRequestHeader("Content-Type", "application/x-www-form-urlencoded")
Call .Send(strQueryString)
strResponse = .ResponseText
End With
Set objSpider = Nothing
' Notify user of success/failure
If Not strResponse = "Login Failed" Then
lngMemberID = strResponse
Response.Write("MemberID = " & lngMemberID)
Response.Cookies("MinServerUser").Path = "/"
Response.Cookies("MinServerUser")("Name") = strLoginName
Response.Cookies("MinServerUser")("Pword") = strLoginPassword
Else
Response.Write("Login Failed: " & strResponse)
End If
end function
function LoginBox()
<FORM method="post" action="call function CheckLogin()">
Login Name: <INPUT name="LoginName" size="20"><BR>
Login Password: <INPUT name="LoginPassword" type="Password" size="20"><BR>
<INPUT type="submit" value="Login">
</FORM>
end function
%>
og her den sidste fil som kan gives til eksterne serveradministratorer
<INCLUDE:http//minserver2.dk/functions.asp>
call LoginBox()