VBScript Null Session Variable String Comparison

Environment: ASP, IIS, server-side VBScript

Problem

A string comparison where I compared a Session variable to a form field would return a "strings are equal" type of result when the Session variable was null and the form field value was a non-null string. The logic I used was initially:

IF Session("myVar") <> Request.Form("my_var") THEN
' no match
ELSE
' strings matched
END IF

I replaced the IF condition like this:

IF (StrComp(Session("myVar"), Request.Form("my_var")) <> 0) THEN

but it still returned a string match when the Session variable was null and the form field value was a non-null string.

The Fix

Status: Fixed

I forced the Session variable into a string-type page-level variable, like this:

session_myVar = "" & Session("myVar")

I then used session_myVar in the comparisons instead of using the Session variable directly.


Creative Commons License
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 Unported License.

Post new comment

The content of this field is kept private and will not be shown publicly.
  • E-Mail addresses are hidden with reCAPTCHA Mailhide.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd> <blockquote> <img> <h4> <h5> <h6> <s> <u> <span>
  • Lines and paragraphs break automatically.
  • You may link to Gallery2 items on this site using a special syntax.

More information about formatting options

CAPTCHA
This question is for testing whether you are a human visitor and to prevent automated spam submissions.

 





My Books