Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Tracking pages using cookies

Status
Not open for further replies.

Vermontecher

Programmer
Feb 13, 2005
14
0
0
US
Hello,
This may sound very basic to most but it is something that I have not had to do before and I would like to start using this. Here is what I want to do. I have built a web site with many pages. It is user based and a user has to sign in to get access to the inner pages. The sign in works fine. What I need to do is this... When a visitor enters the site there are links they can select. If they are not logged in they are redirected to the login page. (Works fine) When they then enter their username and password they are redirected back to the home page. What I want to do is have the login page then direct them to whatever link they selected. Can I get some help with this please, it will be greatly appreciated. All files are ASP, database is Access 2000 and I would like to do this using cookies I think. If there is another better way then I would have no problem trying something else.

Thanks all,
Vermontecher
 
The page that redirects someone to the login page is they are not logged in can set a session variable to provide the validation page a URL to go to.

Something like this on each page:

If not logged in then
Session("pagetogoto") = Server.Variables("URL")
Response.Redirect "login.asp"
End If

Then on the login validation page, with successful login, you use:

Dim pagetogoto

pagetogoto = "mainpage.asp"

If Session("pagetogoto") Then
pagetogoto = Session("pagetogoto")
Session("pagetogoto") = ""
End If

Response.Redirect pagetogoto

Lee
 

Hello Lee,
Thanks for your help. Here is what I have done and the results. First, I tried to use the code as you submitted it but that didn't work, I got an error saying that Server.Variable was not supported. I changed your code as follows...

If not logged in then
Session("pagetogoto") = Server.Variables("URL")
Response.Redirect "login.asp"
End If

TO

If Session("status") <> "login" Then
Session("pagetogoto") = Request.ServerVariables("HTTP_REFERER")
Response.Redirect "login.asp"
End If

That seems to work with no errors. Now when I go to the next page I received more errors so I changed your code as follows...

Dim pagetogoto

pagetogoto = "mainpage.asp"

If Session("pagetogoto") Then
pagetogoto = Session("pagetogoto")
Session("pagetogoto") = ""
End If

Response.Redirect pagetogoto

TO

Dim pagetogoto

pagetogoto = "default.asp"

If Session("pagetogoto") = "" Then
pagetogoto = Session("pagetogoto")
Session("pagetogoto") = ""
End If

Response.Redirect pagetogoto

It doesn't look right but that is the only way I can get it to work at all. The problem is when I try to go to the login page it just comes back to the default page. I can see that I have a loop of sorts going on here but I don't know how to resolve it. Thanks again for your help, I appreciate you taking the time to assist me with this.

Vermontecher
 
Anyone out there able to help with this would be greatly appreciated... Thanks for your assistance in advance.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top