 |
Classic ASP XML Using ASP 3 and XML. See also the XML category for more XML discussions not relating to ASP. NOT for ASP.NET 1.0, 1.1, or 2.0 |
Welcome to the p2p.wrox.com Forums.
You are currently viewing the Classic ASP XML section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
|
|
|

November 18th, 2003, 02:57 AM
|
Authorized User
|
|
Join Date: Nov 2003
Posts: 20
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
If Request.Cookies("username") <> "" Then
'Execute login validation here using values from cookies
'Get values from cookies
sUsername = Request.Cookies("username")
sPassword = Request.Cookies("password")
'call doLogin to validate login,
'returns true for valid login
If doLogin(sUsername, sPassword) Then
Response.Redirect("index.asp")
End If
End If
is that what you are talking about doLogin(), i dont knowwhere to put it, its jst on the login page the now?
|

November 18th, 2003, 01:12 PM
|
 |
Friend of Wrox
|
|
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
|
|
I was suggesting creating a login function because you need to do this login routing in two places: once where you handle processing the user login (processuser.asp) and once on your index page where you try to do a auto login based on the cookie values. there's no reason to duplicate the login routine on both page when you can just create a function for it and call the function from both places.
Maybe this will help. I made a small adjustment to your XPath query based on what I'm assuming your XML structure to be.
If this is what your XML structure looks like
<records>
<details>
<username>username1</username>
<password>password1</password>
</details>
<details>
<username>username2</username>
<password>password2</password>
</details>
</records>
than this should work for you:
File: login.inc
<%
Function doLogin(sUserName, sPassword)
Dim xmlDocument, path, nodes
set xmlDocument = CreateObject("MSXML2.FreeThreadedDOMDocument")
xmlDocument.async = "false"
xmlDocument.load(Server.MapPath("/speirsy/db/user.xml"))
xmlDocument.setProperty "SelectionLanguage", "XPath"
path = "/records/details[username='" & sUserName & "' and password='" & sPassword & "']"
set nodes = xmlDocument.selectNodes(path)
If nodes.length > 0 Then
'User found!
Response.Cookies("username") = sUsername
Response.Cookies("password") = sPassword
Response.Redirect "log.asp"
Else
'No user found :-(
doLogin = False
End If
End Function
%>
File: index.asp
<%
If Request.Cookies("username") <> "" Then
'Execute login validation here using values from cookies
'Get values from cookies
sUsername = Request.Cookies("username")
sPassword = Request.Cookies("password")
'call doLogin to validate login,
'returns true for valid login
doLogin(sUsername, sPassword)
'doLogin will redirect you automatically if login succeeds
End If
%>
[rest of the page here: show login form]
File: processuser.asp
<%
doLogin(Request.Form("userQuery"), Request.Form("passwordEntry"))
'doLogin will redirect automatically, so if it fails, this page will be seen
%>
please enter a valid password</br></br>
<a href='index.asp'>Back to login page</a>
Hope this helps.
Peter
------------------------------------------------------
Work smarter, not harder.
|

November 18th, 2003, 06:18 PM
|
Authorized User
|
|
Join Date: Nov 2003
Posts: 20
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
mate wot does
mean?
sorry
|

November 18th, 2003, 06:28 PM
|
 |
Friend of Wrox
|
|
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
|
|
That is how you include a file in an ASP script. Commonly used for including files with common code into a script.
Peter
------------------------------------------------------
Work smarter, not harder.
|

November 18th, 2003, 06:28 PM
|
Authorized User
|
|
Join Date: Nov 2003
Posts: 20
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
my code for index asp is
<%@ Language="VBScript" %>
<% option explicit %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<?xml version="1.0" encoding="iso-8859-1"?>
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>: . Welcome to dezine . :</title>
<%
Function doLogin(sUserName, sPassword)
Dim xmlDocument, path, nodes
set xmlDocument = CreateObject("MSXML2.FreeThreadedDOMDocument")
xmlDocument.async = "false"
xmlDocument.load(Server.MapPath("/speirsy/db/user.xml"))
xmlDocument.setProperty "SelectionLanguage", "XPath"
path = "/records/details[username='" & sUserName & "' and password='" & sPassword & "']"
set nodes = xmlDocument.selectNodes(path)
If nodes.length > 0 Then
'User found!
Response.Cookies("username") = sUsername
Response.Cookies("password") = sPassword
Response.Redirect "log.asp"
Else
'No user found :-(
doLogin = False
End If
End Function
If Request.Cookies("username") <> "" Then
'Execute login validation here using values from cookies
'Get values from cookies
sUsername = Request.Cookies("username")
sPassword = Request.Cookies("password")
'call doLogin to validate login,
'returns true for valid login
doLogin(sUsername, sPassword)
'doLogin will redirect you automatically if login succeeds
End If
%>
<script type="text/javascript">
function validate() {
if (document.form1.userQuery.value.length < 1) {
document.form1.userQuery.focus();
window.alert("Please enter a Username.");
return false;
}
if (document.form1.passwordEntry.value.length < 1) {
document.form1.passwordEntry.focus();
window.alert("Please enter a password.");
return false;
}
}
</script>
</head>
<body>
<p> Welcome to dezine, a portal site where you can search for tutorials and also reviews of the latest products that multimedia and web designers use today</p>
<p> In order to use the site, please enter your details and then press the submit button</p>
<table align="center">
<form name=form1 method="POST" action="user.asp" method="post" onsubmit="return validate()">
<tr>
<td>Username:</td>
<td><input type="text" name="userQuery" /></td>
</tr>
<tr>
<td>Password:</td>
<td><input type="password" name="passwordEntry" /></td>
</tr>
<tr>
<td align="center" colspan="2"><input type="submit" value="Login" /></td>
</tr>
</form>
</table>
<br />
<table align="center">
<tr>
<td> <a href="signup.html">Join</a></td>
</tr>
<tr>
<td> <a href="javascript: submitReminder();">Lost password</a></td>
</tr>
</table>
<p> </p>
<p> </p>
<p> </p><p> </p>
<p> </p>
<p> </p>
<p> </p><p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p>Copyright 2003 Craig Speirs</p>
</body>
</html>
and is not working
the error that appears is Active Server Pages error 'ASP 0126'
Include file not found
/speirsy/web_coursework/index.asp, line 13
The include file 'login.inc' was not found.
is login.inc to be saved ina separate file ? like login.inc contains all that code u gave me, also is that the only code i need for process.asp?
thanks again sir
craig
|

November 18th, 2003, 06:32 PM
|
 |
Friend of Wrox
|
|
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
|
|
That is pretty much all you need for process ASP. If the login succeeds it redirects to the next page. If it fails you show the error with the link back to the index (login) page. You probably should format it nicely in a full set of html tags and all, I just wanted to show you what you had to do.
Yes, you need to create a new file: login.inc. This is the file that the other two files "include". Your doLogin() function needs to live in that file so that both the processuser.asp and index.asp pages can access that function.
Peter
------------------------------------------------------
Work smarter, not harder.
|

November 18th, 2003, 06:51 PM
|
Authorized User
|
|
Join Date: Nov 2003
Posts: 20
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
still problems
my index.asp includes the code
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>: . Welcome to dezine . :</title>
<%
If Request.Cookies("username") <> "" Then
'Execute login validation here using values from cookies
'Get values from cookies
sUsername = Request.Cookies("username")
sPassword = Request.Cookies("password")
'call doLogin to validate login,
'returns true for valid login
doLogin sUsername, sPassword
'doLogin will redirect you automatically if login succeeds
End If
%>
<script type="text/javascript
but an error appears asking Microsoft VBScript compilation error '800a03f6'
Expected 'End'
/speirsy/web_coursework/index.asp, line 24
i enter an end then it asks for an end if
neverending i tellu
my login.inc is
<%
Function doLogin(sUserName, sPassword)
Dim xmlDocument, path, nodes
set xmlDocument = CreateObject("MSXML2.FreeThreadedDOMDocument")
xmlDocument.async = "false"
xmlDocument.load(Server.MapPath("/speirsy/db/user.xml"))
xmlDocument.setProperty "SelectionLanguage", "XPath"
path = "/records/details[username='" & sUserName & "' and password='" & sPassword & "']"
set nodes = xmlDocument.selectNodes(path)
If nodes.length > 0 Then
'User found!
Response.Cookies("username") = sUsername
Response.Cookies("password") = sPassword
Response.cookies("username").Expires=date+9999
Response.cookies("password").Expires=date+9999
%>
Response.Redirect "log.asp"
Else
'No user found :-(
doLogin = False
End If
End Function
%>
and my user.asp ( name has been changed from process.asp) is
<%@ Language="VBScript" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<?xml version="1.0" encoding="iso-8859-1"?>
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title></title>
<%
doLogin Request.Form("userQuery"), Request.Form("passwordEntry")
'doLogin will redirect automatically, so if it fails, this page will be seen
%>
please enter a valid password</br></br>
<a href='index.asp'>Back to login page</a
</body>
</html>
|

November 18th, 2003, 07:28 PM
|
 |
Friend of Wrox
|
|
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
|
|
What's the %> doing in the middle of the include file?
Peter
------------------------------------------------------
Work smarter, not harder.
|

November 19th, 2003, 07:36 AM
|
Authorized User
|
|
Join Date: Nov 2003
Posts: 20
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
now its sayin
Microsoft VBScript runtime error '800a01f4'
Variable is undefined: 'sUserName'
/speirsy/web_coursework/index.asp, line 17
my code for index.asp is
<%@ Language="VBScript" %>
<% option explicit %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<?xml version="1.0" encoding="iso-8859-1"?>
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>: . Welcome to dezine . :</title>
<%
If Request.Cookies("username") <> "" Then
'Execute login validation here using values from cookies
'Get values from cookies
sUsername = Request.Cookies("username")
sPassword = Request.Cookies("password")
'call doLogin to validate login,
'returns true for valid login
doLogin sUsername, sPassword
'doLogin will redirect you automatically if login succeeds
End If
%>
<script type="text/javascript">
function validate() {
if (document.form1.userQuery.value.length < 1) {
document.form1.userQuery.focus();
window.alert("Please enter a Username.");
return false;
}
if (document.form1.passwordEntry.value.length < 1) {
document.form1.passwordEntry.focus();
window.alert("Please enter a password.");
return false;
}
}
</script>
</head>
<body>
<p> Welcome to dezine, a portal site where you can search for tutorials and also reviews of the latest products that multimedia and web designers use today</p>
<p> In order to use the site, please enter your details and then press the submit button</p>
<table align="center">
<form name=form1 method="POST" action="user.asp" method="post" onsubmit="return validate()">
<tr>
<td>Username:</td>
<td><input type="text" name="userQuery" /></td>
</tr>
<tr>
<td>Password:</td>
<td><input type="password" name="passwordEntry" /></td>
</tr>
<tr>
<td align="center" colspan="2"><input type="submit" value="Login" /></td>
</tr>
</form>
</table>
<br />
<table align="center">
<tr>
<td> <a href="signup.html">Join</a></td>
</tr>
<tr>
<td> <a href="javascript: submitReminder();">Lost password</a></td>
</tr>
</table>
<p> </p>
<p> </p>
<p> </p><p> </p>
<p> </p>
<p> </p>
<p> </p><p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p>Copyright 2003 Craig Speirs</p>
</body>
</html>
my code for login.inc is same as ures and likewise for process.asp
thanks
|
|
 |