PDA

View Full Version : problem with session variables


jharnisch
04-18-2004, 03:10 PM
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

glenngv
04-19-2004, 05:12 AM
First, specify the request collection to use when retrieving form data.
Use Request.QueryString if form method of previous page is GET or Request.Form if method is POST. This will make your code more efficient and avoids possible conflicts with other request collection that have the same key.

Ok, back to your real problem. To help you debug your code, use Response.Write to check the values.

Response.Write "Encrypt:" & Request.Form("Encrypt") & "<br />"
Response.Write "KeyCheck:" & Session("KeyCheck") & "<br />"
If Request.Form("Encrypt") <> Session("KeyCheck") Then
...