Create an account

Very important

  • To access the important data of the forums, you must be active in each forum and especially in the leaks and database leaks section, send data and after sending the data and activity, data and important content will be opened and visible for you.
  • You will only see chat messages from people who are at or below your level.
  • More than 500,000 database leaks and millions of account leaks are waiting for you, so access and view with more activity.
  • Many important data are inactive and inaccessible for you, so open them with activity. (This will be done automatically)


Thread Rating:
  • 610 Vote(s) - 3.5 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Request.ServerVariables("..") returns undefined when assigned to a variable yet its value can be displayed via Response.Write("..")

#1
I am trying to retrieve the user's IP address and assign it to a variable:

```
var ipAddress = Request.ServerVariables("HTTP_X_FORWARDED_FOR") ||
Request.ServerVariables("REMOTE_ADDR") ||
Request.ServerVariables("HTTP_HOST");

Response.Write(Request.ServerVariables("HTTP_HOST") + "<br />\n\n"); // produces "localhost"
Response.Write(Request.ServerVariables("REMOTE_ADDR") + "<br />\n\n"); // produces "::1"
Response.Write(Request.ServerVariables("HTTP_X_FORWARDED_FOR") + "<br />\n\n"); // produces "undefined"
Response.Write("ipAddress = " + typeof ipAddress + " " + ipAddress + "<br />\n\n"); // produces "ipAddress = object undefined"

```

I am using JScript for Classic ASP. I am unsure as to what to do at this point. Can anyone help?

Thanks
Reply

#2
I solved the problem with obtaining the IP address, and the truthyness/falsyness of JScript is a complete and utter nightmare.

```
if (!String.prototype.isNullOrEmpty) {
String.isNullOrEmpty = function(value) {
return (typeof value === 'undefined' || value == null || value.length == undefined || value.length == 0);
};
}

var ipAddress = Request.ServerVariables("HTTP_X_FORWARDED_FOR") ||
Request.ServerVariables("REMOTE_ADDR") ||
Request.ServerVariables("HTTP_HOST");

function getIPAddress() {
try {
if (String.isNullOrEmpty(ipAddress)) {
ipAddress = Request.ServerVariables("HTTP_X_FORWARDED_FOR");
}

if (String.isNullOrEmpty(ipAddress)) {
ipAddress = Request.ServerVariables("REMOTE_ADDR");
}

if (String.isNullOrEmpty(ipAddress)) {
ipAddress = Request.ServerVariables("HTTP_HOST");
}
} catch (e) {
Response.Write("From getIPAddress(): " + e.message);
hasErrors = true;
} finally {
return ipAddress;
}
}


ipAddress = getIPAddress();
Response.Write("ipAddress = " + typeof ipAddress + " " + ipAddress + "<br />\n\n"); // produces "object localhost"
```


Reply

#3
Things work in ASP with JScript a little bit different than ASP with VBScript.

Since everything is an object in JavaScript, with `var ipAddress = Request.ServerVariables("HTTP_X_FORWARDED_FOR")` you get an object reference instead of a string value because like most of other `Request` collections, the `ServerVariables` is a collection of `IStringList` objects

So, to make that short-circuit evaluation work as you expect, you need to play with the values, not the object references.

You can use the `Item` method that returns the string value of `IStringList` object if there's a value (the key exists), otherwise it returns an `Empty` value that evaluated as `undefined` in JScript.

```js
var ipAddress = Request.ServerVariables("HTTP_X_FORWARDED_FOR").Item ||
Request.ServerVariables("REMOTE_ADDR").Item ||
Request.ServerVariables("HTTP_HOST").Item;
```
Reply



Forum Jump:


Users browsing this thread:
1 Guest(s)

©0Day  2016 - 2023 | All Rights Reserved.  Made with    for the community. Connected through