fiaf08
05-18-2007, 05:57 PM
Hi,
I have a login pages right now that prompts the user for login and password and redirect the authenticated user to a URL (see code sample below). Now instead of this I would like it to pick a URL (different for each user) listed in my access database (URLredirect) and redirect them to their personalized homepage. How can I solve this problem? Can anyone guide me in the right direction? Thanks
<%
Else
strSQL = "SELECT * FROM tblLoginInfo " _
& "WHERE username='" & Replace(Request.Form("login"), "'", "''") & "' " _
& "AND password='" & Replace(Request.Form("password"), "'", "''") & "';"
Set cnnLogin = Server.CreateObject("ADODB.Connection")
cnnLogin.Open("DRIVER={Microsoft Access Driver (*.mdb)};" _
& "DBQ=" & Server.MapPath("Mylogin.mdb"))
Set rstLogin = cnnLogin.Execute(strSQL)
If Not rstLogin.EOF Then
%> <meta HTTP-EQUIV="REFRESH" content="0; url=(URL address)">
<%
Else
%> <p>
<font size="2" face="Arial" color="#FF0000"><strong>
Login Failed
</strong><strong style="font-weight: 400">
- Please verify username and password and try again.
<a href="login_db.asp">Click Here</a></strong></font></p>
<%
'Response.End
End If
' Clean Up
rstLogin.Close
Set rstLogin = Nothing
cnnLogin.Close
Set cnnLogin = Nothing
End If
%>
TheShaner
05-18-2007, 07:44 PM
If Not rstLogin.EOF Then
Response.Redirect rstLogin("URLredirect")
Else
...
And make sure you put Response.Buffer = True at the top of your page or it won't redirect properly!
Also, in your SQL, no need to use the * and grab all fields. Just grab the URLredirect field:
strSQL = "SELECT URLredirect FROM tblLoginInfo " _
& "WHERE username='" & Replace(Request.Form("login"), "'", "''") & "' " _
& "AND password='" & Replace(Request.Form("password"), "'", "''") & "';"
-Shane
fiaf08
05-18-2007, 08:55 PM
Just tried it. what it does is that it adds #URL# at the end of the login page URL. For instance, if my login page is:
http://mydomain/login.asp
I'm getting:
http://mydomain/login.asp#abc.com# (abc.com being the url indicated for this user in my Access table)
but i'm not being redirected to abc.com
Am I missing something? Let me know. Thanks again for your answer.
By the way, here's the code for the entire page:
<%response.Buffer=true%>
<%
Dim cnnLogin
Dim rstLogin
Dim strUsername, strPassword
Dim strSQL
%>
<html>
<head><title>Gateway</title>
</head>
<body bgcolor="#FFFFFF">
<%
If Request.Form("action") <> "validate_login" Then
%>
<form action="login.asp" method="post">
<input type="hidden" name="action" value="validate_login" />
<table border="0">
<tr>
<td align="right"><font face="Arial" size="2">E-Mail Address:</font></td>
<td><font face="Arial"><input type="text" name="login" size="20" /></font></td>
</tr>
<tr>
<td align="right"><font face="Arial" size="2">Member ID:</font></td>
<td><font face="Arial"><input type="password" name="password" size="20" /></font></td>
</tr>
<tr>
<td align="right"></TD>
<td><font face="Arial"><input type="submit" VALUE="Login" /></font></td>
</tr>
</table>
</form>
<%
Else
strSQL = "SELECT URLredirect FROM tblLoginInfo " _
& "WHERE username='" & Replace(Request.Form("login"), "'", "''") & "' " _
& "AND password='" & Replace(Request.Form("password"), "'", "''") & "';"
Set cnnLogin = Server.CreateObject("ADODB.Connection")
cnnLogin.Open("DRIVER={Microsoft Access Driver (*.mdb)};" _
& "DBQ=" & Server.MapPath("login.mdb"))
Set rstLogin = cnnLogin.Execute(strSQL)
If Not rstLogin.EOF Then
Response.Redirect rstLogin("URLredirect")
Else
%>
<p>
<font size="2" face="Arial" color="#FF0000"><strong>
Login Failed
</strong><strong style="font-weight: 400">
- Please verify username and password and try again.
<a href="login_db.asp">Click Here</a></strong></font></p>
<%
'Response.End
End If
' Clean Up
rstLogin.Close
Set rstLogin = Nothing
cnnLogin.Close
Set cnnLogin = Nothing
End If
%>
</body>
</html>
glenngv
05-18-2007, 09:58 PM
You should put http://
Response.Redirect "http://" & rstLogin("URLredirect")
TheShaner
05-18-2007, 10:01 PM
Well, it all depends on what is stored in your URLredirect field and what directory you're currently in.
For the following examples, your login page is within the http://domain.com root directory.
If URLredirect is abc.com, it thinks it's a page within that directory and will end up being http://domain.com/abc.com. So you will have to do:
Response.Redirect "http://" & rstLogin("URLredirect") 'http://abc.com
Or change the values in URLredirect to have full addresses.
If it's a page within your directory, like user_page.asp, then you'd do:
Response.Redirect rstLogin("URLredirect") 'http://domain.com/user_page.asp
If the page isn't within that directory, you'd do:
Response.Redirect "users/" & rstLogin("URLredirect") 'http://domain.com/users/user_page.asp
OR
Response.Redirect "http://domain.com/users/" & rstLogin("URLredirect") 'http://domain.com/users/user_page.asp
-Shane
fiaf08
05-18-2007, 10:33 PM
Ok that makes sense ... I'm going to try that over the weekend and get back to you. Thanks again.
fiaf08
05-18-2007, 10:38 PM
One more thing ... in my example, abc.com (the tv channel) is a real website. I need to redirect outside my domain.
fiaf08
05-18-2007, 10:45 PM
OK it is working now ... somebody advised to switch the field type from hyperlink to text in my access db. Thanks again for your help.