Print Page | Close Window

problem with session variables

Printed From: Web Wiz Forums
Category: General Discussion
Forum Name: Classic ASP Discussion
Forum Description: Discussion on Active Server Pages (Classic ASP).
URL: https://forums.webwiz.net/forum_posts.asp?TID=10041
Printed Date: 31 March 2026 at 4:31pm
Software Version: Web Wiz Forums 12.08 - https://www.webwizforums.com


Topic: problem with session variables
Posted By: jharnisch
Subject: problem with session variables
Date Posted: 18 April 2004 at 9:55am
Hello,

I am having a problem I think with session variables. On a page I have 4 buttons a user can click from and each of those buttons has a random number associated with it. When the timer reaches zero, one of the buttons is able to be clicked on and a user earns a credit. It works most of the time, However some times it does not store the correct random number for the button. Here is some of the code:

This picks which button will be allowed to click on:

Randomize Timer 'Randomize Function
rndNumber = Int((RND * 4)+1)

If rndNumber = 1 then
Session("KeyCheck") = rndKey1
End If

If rndNumber = 2 then
Session("KeyCheck") = rndKey2
End If

If rndNumber = 3 then
Session("KeyCheck") = rndKey3
End If

If rndNumber = 4 then
Session("KeyCheck") = rndKey4
End If

This next part then takes the random number associated with the button the user clicks and compares it to button that was chosen:

If Request("Encrypt") <> Session("KeyCheck") Then

If it does not match the user is taken back to the logon screen. I cannot figure out why it works most of the time and then there are a few times where the user gets redirected back to the login page even though they clicked on the correct button.

Any help would be appreciated,

Jeff Harnisch



Replies:
Posted By: ljamal
Date Posted: 18 April 2004 at 11:35am
Sessions a cookies, it may be that the user is denying the cookie.

-------------
L. Jamal Walton

http://www.ljamal.com/" rel="nofollow - L. Jamal Inc : Web/ Print Design and ASP Programming


Posted By: dj air
Date Posted: 18 April 2004 at 11:41am

it also could be that the rndNumber generated is bigger than 4,

have you response.write rndNumber

which will give you the rndNumber number that has been generated



Posted By: pmormr
Date Posted: 18 April 2004 at 12:43pm

why don't you change this...

If rndNumber = 1 then
Session("KeyCheck") = rndKey1
End If

If rndNumber = 2 then
Session("KeyCheck") = rndKey2
End If

If rndNumber = 3 then
Session("KeyCheck") = rndKey3
End If

If rndNumber = 4 then
Session("KeyCheck") = rndKey4
End If

into this...

Select Case rndNumber
   Case 1:
      Session("KeyCheck") = rndKey1
   Case 2:
      Session("KeyCheck") = rndKey2
   Case 3:
      Session("KeyCheck") = rndKey3
   Case 4:
      Session("KeyCheck") = rndKey4
End Select

that makes it a little easier to read... btw... don't whine if it gives you an error... i'm not sure if you need the colin after the case 1... stuff



-------------
Paul A Morgan

http://www.pmorganphoto.com/" rel="nofollow - http://www.pmorganphoto.com/


Posted By: Mart
Date Posted: 18 April 2004 at 12:45pm
You don't need a colon, remove the colon after case x


Posted By: jharnisch
Date Posted: 19 April 2004 at 3:38pm

The problem isnt with generating the random number. It picks a number from 1 to 4. Any other ideas?

Thanks

 




Print Page | Close Window

Forum Software by Web Wiz Forums® version 12.08 - https://www.webwizforums.com
Copyright ©2001-2026 Web Wiz Ltd. - https://www.webwiz.net