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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

problems with session vars

Status
Not open for further replies.

LandMonster

Programmer
Feb 4, 2002
11
CA
I'm trying to use a session variable to limit access to a page on my site. when a user logs in, I set the var to true. then on the protected page I check the variable for false. if false I redirect back to the login page. The problem is, when I try to check that var, my page won't load. here is my code:

global.asa
______________________________________________
<script language=&quot;vbscript&quot; runat=&quot;server&quot;>

sub Application_OnStart
end sub

sub Application_OnEnd
end sub

sub Session_OnStart
session(&quot;sValid&quot;)=FALSE
end sub

sub Session_OnEnd
end sub
</script>


login.asp
___________________________________________________
session(&quot;sValid&quot;)=TRUE
Response.Redirect(&quot;post.asp&quot;)
'This is the snippet of code where I set my session variable

post.asp
_____________________________________________________
<%

If Session(&quot;sValid&quot;) = FALSE Then
Response.Redirect (&quot;login.asp&quot;)
Else
Response.Write &quot;<!-- Validated at &quot; & cstr(Now()) & &quot; -->&quot;
End If
%>

Without that bit of code in my post page it loads fine, writes to the db and all that good stuff. But when I try to open the page with this code it in, it gives me an error and won't load at all.

Can somebody let me know what I'm doing wrong?

Thanks
 
The only error I get on the page is HTTP 500. the generic IE error.
 
Try removing the exclamation mark and see what it does:
Response.Write &quot;<-- Validated at &quot; & cstr(Now()) & &quot; -->&quot;
 
I removed the whole else statement and it still doesn't work.
Also, a friend suggested that I change the var to hold a string instead of a boolean. I tried that and it still doesn't work.
 
Well, I am not sure why you are getting the 500 error, but I do see one potential problem.

Change your code to the following:

If Session(&quot;sValid&quot;) <> &quot;true&quot; Then
Response.Redirect (&quot;login.asp&quot;)
Else
Response.Write &quot;<!-- Validated at &quot; & cstr(Now()) & &quot; -->&quot;
End If

Also, make sure you uncheck the &quot;show friendly HTTP errors&quot; under Tools -> Internet Options -> Advanced. This will make the browser show the actual technical error.

HTH,
Mark
 
meckeard, thank you. I unchecked that option (I didn't even know about it) and it showed me my errors. I also changed it to a <> and not my validation works. Much appreciated.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top