The forums have permanently moved to forum.kirupa.com. This forum will be kept around in read-only mode for archival purposes. To learn how to continue using your existing account on the new forums, check out this thread.


Results 1 to 5 of 5

Thread: Retrieving Cookies

  1. #1
    228
    posts
    All the small things!

    Retrieving Cookies

    Hello everyone! I just figured out how to set a cookie and everything, now Im working on making certain pages that are the users updatable by them.
    Now I think I have set the cookie, what I want to do on my fake blog site is make it so that if someone is logged on they can update there webspace and only their webspace. The cookie should have the users ID_no in it, I want to make an IF THEN statement saying, "if the cookie IDnumber is the same as the page IDnumber then display update button. Make sense? here is my code:

    Login:

    Code:
    <html>
    Login<head>
    <body text="black">
    <font face="arial">
    <center>
    <%
    If request("error")="1" then
    response.write "Your username was not found in our database<br>"
    End if
    If request("error")="2" then
    response.write "Your password did not match<br>"
    End if
    If request("error")="3" then
    response.write "You must supply both a username and password<br>"
    End if
    %>
    <br>
    Please use your username and password to login to our secure area.<br>
    <form method="post" action="verify.asp" name="form">
    Username: <input type="text" name="username">
    
    Password: <input type="password" name="password">
    
    <input type="submit" name="submit" value="submit">
    </form>
    
    </font>
    </center>
    </body>
    and the Verify page:
    Code:
    <%
    Dim DatabaseConn
    Dim RecordSet
    Dim strSQL 
    Dim foundIt
    Dim objConn
    Dim password
    Dim username
    
    Set DatabaseConn = Server.CreateObject("ADODB.Connection")
    DatabaseConn.Open "DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=" & Server.MapPath("profile.mdb")
    Set RecordSet = Server.CreateObject("ADODB.Recordset")
    strSQL = "SELECT personal.username, personal.password, personal.ID_no, * FROM personal"
    RecordSet.Open strSQL, DatabaseConn
    
    username=trim(request.form("username"))
    password=trim(request.form("password"))
    If username = "" or password = "" then
    response.redirect ("login.asp?error=3")
    End If
    
    foundIt=False
    Do Until RecordSet.EOF OR foundIt
    If (StrComp(RecordSet("username"), username, vbTextCompare) = 0) Then
    foundIt=True
    Else
    RecordSet.MoveNext
    End If
    Loop
    If Not foundIt Then
    RecordSet.Close
    Set RS = Nothing
    objConn.Close
    Set objConn = Nothing
    response.redirect("login.asp?error=1")
    End If
    
    If Not (StrComp(RecordSet("password"), password, vbBinaryCompare) = 0) Then
    RecordSet.Close
    Set RecordSet = Nothing
    objConn.Close
    Set objConn = Nothing
    Response.Redirect("login.asp?error=2")
    
    Else Session("Valid") = Request("username")
    End If
    %>
    <%
    ID=RecordSet("ID_no")
    Response.Cookies("ID") = RecordSet("ID_no")
    %>
    <%Response.Redirect("welcome.asp?ID=" & RecordSet("ID_no"))%>
    Code on updatable pages:

    Code:
    <%
    Dim DatabaseConn
    Dim RecordSet
    Dim strSQL 
    Dim RecordNo
    
    RecordNo = (Request.QueryString("ID"))
    Set DatabaseConn = Server.CreateObject("ADODB.Connection")
    DatabaseConn.Open "DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=" & Server.MapPath("profile.mdb")
    Set RecordSet = Server.CreateObject("ADODB.Recordset")
    strSQL = "SELECT personal.* FROM personal WHERE ID_no=" & RecordNo &""
    RecordSet.CursorType = 2
    RecordSet.LockType = 3
    RecordSet.Open strSQL, DatabaseConn
    %>
    
    
    <!---------------------------------Page Start------------------------------------->
    
    
    <html>
    <body text="black" bgcolor="<%=RecordSet("bgColor")%>">
    
    <center>
    
    
    <table width="600" cellpadding="0" cellspacing="0" border="0">
    <tr>
    <td align="right">
    <font face="arial" size="2">
    <form name="form" action="update.asp" method="post">
    <input type="hidden" name="ID_no" value="<% = RecordSet("ID_no")%>">
    
    <%
    Response.Buffer=TRUE
    if Request.Cookies("ID") <> "ID_no" then
    %>
    
    <input type="submit" name="Submit" value="Update">
    
    <% else %>
    
    </form>
    this is only the header, I know how to write an If then statement I just need to know how to make Cookie match with the id of the site and if it doesnt just display the page.
    Thanks
    Fidelity88

  2. #2
    hmmmm............
    i want a cookie
    sounds tasty
    my smilies: K-Emmys 05: Best newbie, FOUNDER OF THE KEMMY'S
    Deviantart I am ŦĦĸ7!!

  3. #3
    228
    posts
    All the small things!
    hehe, fo real!

  4. #4
    what a bunch of code to do what php does in 1 line!!! god i love asp...

    ps: just joking still remember those days when asp was my way of life...

  5. #5
    228
    posts
    All the small things!
    Yeah man, Im a new programer so Im just using what I know at this point and this is a good starting point it seems like, so yeah I know Im old school!
    Hahahahaha
    Fidelity88

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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

Home About kirupa.com Meet the Moderators Advertise

 Link to Us

 Credits

Copyright 1999 - 2012