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 6 of 6

Thread: Session Cookies

  1. #1
    New Coder
    Join Date
    Aug 2006
    Posts
    28
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Session Cookies

    I'm new to using session cookies and need just a bit of help. On the introduction page to my project, I'm setting:

    Code:
    <%@ Language=VBScript %>
    <% 
    
    response.cookies("user")="authenticated" 
    
    %>
    Then, on subsequent pages, I'm checking for the cookie, and redirecting if it's not there:

    <%@ Language=VBScript %>
    <%

    If NOT request.cookies("user") = "authenticated" Then
    response.redirect "http://somepage"
    End If


    %>

    What I need to do is incorporate an ignore element (by user-agent or IP) into where it checks for the cookie. For instance, if a user has an IP of 127.0.0.1, it ignores whether they have the cookie or not and lets them view the page.

    The reason I'm doing this is I have a search engine that's crawling the site and it doesn't always go through the front page - therefore, it's getting redirected on most of the pages it sees. So what I'd like to do is have the script see that user-agent or IP, then ignore the cookie requirement.

    Is that possible?

  • #2
    New Coder
    Join Date
    Aug 2006
    Posts
    28
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Anyone?

  • #3
    New Coder
    Join Date
    Nov 2006
    Posts
    47
    Thanks
    2
    Thanked 1 Time in 1 Post
    I don't know if it's possible in regular ASP. I assume it is. I just don't know how. But in .net to get the IP address:

    Dim TheIPAddress As System.Net.IPHostEntry = System.Net.Dns.GetHostByName(System.Net.Dns.GetHostName)

    Dim IPaddress As String = (TheIPAddress.AddressList.GetValue(0).ToString)

    Then you would just have to check IPaddress. If it is a good one then you would authenticate them through code.

    I hope this helps.

  • #4
    teh Moderatorinator
    Join Date
    Sep 2004
    Location
    USA
    Posts
    2,472
    Thanks
    4
    Thanked 40 Times in 40 Posts
    Not sure I understand completely, but you can check out the http_referer:
    http://www.w3schools.com/asp/coll_servervariables.asp

    Let us know how it works out
    Good luck;

  • #5
    New Coder
    Join Date
    Aug 2006
    Posts
    28
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thanks for that link. So I need to: Request.ServerVariables (HTTP_USER_AGENT). Then I need to take that result and compare it with the user-agent I'm expecting (the search crawler). If they match, ignore the redirect and cookie requirement and let the user view the page. If they don't match, follow the routine as normal and redirect if the cookie isn't present. How would I write that?

  • #6
    teh Moderatorinator
    Join Date
    Sep 2004
    Location
    USA
    Posts
    2,472
    Thanks
    4
    Thanked 40 Times in 40 Posts
    Write it just as your other if statement when you redirect, cept this time use the user agent or whatever you are comparing with.

    I think you can get it, if not let us know


  •  

    Posting Permissions

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