Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 8 of 8
  1. #1
    New to the CF scene
    Join Date
    May 2007
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question HELP: Unique URL Redirect from database

    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

    Code:
    <%
     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
     %>

  • #2
    Senior Coder TheShaner's Avatar
    Join Date
    Sep 2005
    Location
    Orlando, FL
    Posts
    1,126
    Thanks
    2
    Thanked 40 Times in 40 Posts
    Code:
    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:
    Code:
    strSQL = "SELECT URLredirect FROM tblLoginInfo " _
     & "WHERE username='" & Replace(Request.Form("login"), "'", "''") & "' " _
     & "AND password='" & Replace(Request.Form("password"), "'", "''") & "';"
    -Shane

  • #3
    New to the CF scene
    Join Date
    May 2007
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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:

    Code:
    <%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>

  • #4
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,043
    Thanks
    0
    Thanked 251 Times in 247 Posts
    You should put http://
    Code:
    Response.Redirect "http://" & rstLogin("URLredirect")

  • #5
    Senior Coder TheShaner's Avatar
    Join Date
    Sep 2005
    Location
    Orlando, FL
    Posts
    1,126
    Thanks
    2
    Thanked 40 Times in 40 Posts
    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:
    Code:
    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:
    Code:
    Response.Redirect rstLogin("URLredirect") 'http://domain.com/user_page.asp
    If the page isn't within that directory, you'd do:
    Code:
    Response.Redirect "users/" & rstLogin("URLredirect") 'http://domain.com/users/user_page.asp
    OR
    Code:
    Response.Redirect "http://domain.com/users/" & rstLogin("URLredirect") 'http://domain.com/users/user_page.asp
    -Shane

  • #6
    New to the CF scene
    Join Date
    May 2007
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Ok that makes sense ... I'm going to try that over the weekend and get back to you. Thanks again.

  • #7
    New to the CF scene
    Join Date
    May 2007
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts
    One more thing ... in my example, abc.com (the tv channel) is a real website. I need to redirect outside my domain.

  • #8
    New to the CF scene
    Join Date
    May 2007
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Thumbs up

    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.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •