need help with adding variable to asp code

Discussion in 'C#' started by gavin watson, Mar 18, 2009.

  1. #1
    hi all, new here, please bear with me!

    I have an .asp page and I have this line of code which is used by an applet to access the ftp server:
    
    <param name = "url" value = " ftp://username:password@www.mydomain.com">
    
    Code (markup):
    but i would like to have a form on the page where the the user could input the variables for the username and password and the then <param name> take them from what the user has inputted on the form.

    I need to do it this way for two reasons, firstly i have various users and secondly i do not want to leave usernames and passwords hardcoded into the page for anyone to look at the source.

    Can anyone help me out with this please?

    Thanks in advance for your time.
     
    gavin watson, Mar 18, 2009 IP
  2. alexpr07

    alexpr07 Active Member

    Messages:
    284
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    73
    #2
    You can have one page asking for username and password:
    
    <form name="login_info" method="post" action="secondpage.asp"
    Username: <input type="text" name="username"><br>
    Password: <input type="text" name="password"><br>
    <input type="submit" value="Submit Username/Password">
    
    Code (markup):
    Second page (asp):
    
    <%
    response.write "<param name = 'url' value = ' ftp://" & request.form("username") & ":" & request.form("password") & "@www.mydomain.com'>"
    
    %>
    
    Code (markup):
    the second page will write <param name = 'url' value = ' ftp://username:password@www.mydomain.com'> to the page where username and password are values from first page.

    Of course, instead of writing that to the page you can do something else with the data like access the database to check if it's valid.
     
    alexpr07, Mar 18, 2009 IP
  3. gavin watson

    gavin watson Member

    Messages:
    28
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    36
    #3
    Hi there, thank you for taking the time to reply and your suggestion.

    Would it be possible to have this on the same page rather than a 'previous' page?

    Would it work if I added the code you have given me to the current page without it having to then forward onto a next page ?

    Thanks again for your help.
     
    gavin watson, Mar 19, 2009 IP
  4. camjohnson95

    camjohnson95 Active Member

    Messages:
    737
    Likes Received:
    17
    Best Answers:
    0
    Trophy Points:
    60
    #4
    try something like:
    
    <form name="login_info" method="post" action="mypage.asp">
    Username: <input type="text" name="username"><br>
    Password: <input type="text" name="password"><br>
    <input type="submit" value="Submit Username/Password">
    </form>
    <%
    If Request.Form("username") <> "" AND Request.Form("password") <> "" Then
          Response.Write "<param name = 'url' value = ' ftp://" & Request.Form("username") & ":" & Request.Form("password") & "@www.mydomain.com'>"
    End If
    %>
    
    Code (markup):
    where the name of the page is mypage.asp
     
    camjohnson95, Mar 21, 2009 IP
  5. camjohnson95

    camjohnson95 Active Member

    Messages:
    737
    Likes Received:
    17
    Best Answers:
    0
    Trophy Points:
    60
    #5
    or if you want it to hide the form after a user enters their info:
    
    <%
    If Request.Form("username") <> "" AND Request.Form("password") <> "" Then
          Response.Write "<param name = 'url' value = ' ftp://" & Request.Form("username") & ":" & Request.Form("password") & "@www.mydomain.com'>"
    Else
    %>
    <form name="login_info" method="post" action="mypage.asp">
    Username: <input type="text" name="username"><br>
    Password: <input type="text" name="password"><br>
    <input type="submit" value="Submit Username/Password">
    </form>
    <% End If %>
    
    Code (markup):
     
    camjohnson95, Mar 21, 2009 IP
  6. gavin watson

    gavin watson Member

    Messages:
    28
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    36
    #6
    thank you all for your replies, i will try them out.

    thansk again, mucha appreciated
     
    gavin watson, Mar 21, 2009 IP