...

View Full Version : Session Cookies



thiazi
12-11-2006, 06:05 PM
I'm new to using session cookies and need just a bit of help. On the introduction page to my project, I'm setting:



<%@ 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?

thiazi
12-12-2006, 03:36 PM
Anyone? :(

EricaStar
12-12-2006, 03:46 PM
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.

Brandoe85
12-12-2006, 03:56 PM
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;

thiazi
12-12-2006, 04:04 PM
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?

Brandoe85
12-12-2006, 05:27 PM
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 :)



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum