Browsing the archives for the vbscript tag.

Web Server’s Variables

Diagnostics, Software Development, Web Development

Here’s another diagnostic tool for web developers: The Web Server’s Variables.  Constantly there are problems with communications or wondering what has been sent by the user’s website to the server and you sometimes wonder what variables might be useful for our programs.  However, I’ve never been too impressed with Google’s responses when looking for matches between Javascript and VBScript comparison between the two, or useful posts for that fact.  Anyway, before I start rambling about the lack of these kinds of posts, let’s get to the post.

As you may already know, I’m a big XML fan for building information blocks that can be used by my applications or communicating between applications.  So, I’ll be building XML blocks based on the variable name as the tags and the value inside.

VBScript – Server Variables

dim ResponseString
For Each ThisServerVar In Request.ServerVariables
       ResponseString = ResponseString + "<" + ThisServerVar + ">" + _
                                         Request.ServerVariables(ThisServerVar) + _
                                         "</" + ThisServerVar + ">"
Next

Javascript – Server Variables

var responseString = "";
for(var i=1; i<=Request.ServerVariables.Count(); i++)
{
   strKeyName = Request.ServerVariables.Key(i);
   strKeyValue = Request.ServerVariables.Item(strKeyName);
   responseString += "<" + strKeyName + ">" + strKeyValue + "</" + strKeyName + ">";
}

Now I can’t tell you where you will need to use this functionality.  But, it is a good diagnostic tool that can be very helpful from time to time when you’re just poking around trying to determine your communications.  Most of the time, you’ll know the exact server variable you’re looking to use.  But sometimes, when you’re programming in 6+ languages in a single week, you’re likely to forget the exact syntax and it’s nice to have something like this to reference.

Enjoy!

Please feel free to post any comments that others may find useful or even something I could use to update this entry.

2 Comments