Empty System.EnvironmentVariable in Linux

I want to get the client’s remote host in my web apps in Linux but System.EnvironmentVariable(“REMOTE_HOST”) is always empty in Xojo but present in perl and php, so that variable is there on the system. Any idea why Xojo isn’t reading it when the others are?

The environment variables get passed to our .cgi script (the one that launches your app), but they are not passed along that way. Take a look at Session.RemoteAddress.

Session.RemoteAddress works but there is no Session.RemoteHost variable in Xojo. Interestingly enough, System.EnvironmentVariable(“REMOTE_ADDR”) always returns the remote address but System.EnvironmentVariable(“REMOTE_HOST”) is always empty even though that environment variable is present on the system. I had expected that System.EnvironmentVariable() would actually be reading the system environment variables.

Ah, well it’s possible that it’s not set.

What about session.Header(“host”) ?

http://en.wikipedia.org/wiki/List_of_HTTP_header_fields

[quote=132927:@Michel Bujardet]What about session.Header(“host”) ?

http://en.wikipedia.org/wiki/List_of_HTTP_header_fields[/quote]
No. The Host header refers to what the client sees as the app. If you typed http://www.xojo.com/ into your browser, the host header would be:

host: www.xojo.com

I know the REMOTE_HOST variable is set because I can read it with perl and php at the same time the web app shows it empty. Is that a Xojo bug?

Well, according to our perl script, we request it (I just looked), so the only thing I can think of is that the web server isn’t passing it to our perl script.

It would be hard to explain why the Xojo perl script is not getting the REMOT_HOST variable when other perl scripts on the same system are. Is it possible that the variable is not being passed from the perl script to the binary?

If you’re getting others, I wouldn’t expect one to be left out, but I can’t say that I’ve ever checked for remote host.

I worked around the problem of the missing REMOTE_HOST variable by writing a perl script to do the DNS lookup, using HTTPSocket.Get to read the script output into a string and then parsing the string to get the remote hostname.

Trying to understand Carl’s question. When he says that “perl scripts” can access the environment variable…does he mean perl scripts launched by his web server? If he’s running XOJO as a CGI app…then the environment variables are limited to those of the web server perhaps “Apache”. If it’s running as a Stand-Alone app…it probably has access to the environment of the user who started the app initially. Perl from the web was always a pain for me because it inherits the environment of the person running the script and doesn’t really allow you to change the environment with a profile script. If you shell-out to run an environment script…as soon as you return…the environment is lost. I’ve often created a ksh script “stub” that sets the environment I want…and then runs the perl script. I call the ksh script from the web / XOJO app. Odd that REMOTE_ADDR works fine though. Maybe I’m just not understanding Carl’s issue.

The problem I’m having with the Xojo web app is that System.EnvironmentVariable(“REMOTE_ADDR”) is always there but System.EnvironmentVariable(“REMOTE_HOST”) is always empty even though I’ve verified that it is actually present in the Apache environment variables. I wrote a perl script to do a lookup on the client IP address by using HTTPSocket.Get() to read the script output into a string after sending Session.RemoteAddress as a parameter for the name lookup. I can’t just read the REMOTE_HOST variable in the perl script because the web app is the remote client thus it would see the server name rather than the web app’s remote client hostname.

That’s a very interesting problem. I can see where that information would be very useful. I may have to try this myself as I expect I may need the same functionality eventually.

I got the same issue…how to get http headers from System.EnvironmentVariable ?

Look on the Session object.

Thanks Greg but I’m on standard CGI and not a webapp

So it is not the same issue…

http://www.tutorialspoint.com/perl/perl_cgi.htm

the thread subject is:
Empty System.EnvironmentVariable in Linux
So that’s what I got.
System.EnvironmentVariable(“REMOTE_ADDR”) -> empty

System.EnvironmentVariable(“REMOTE_HOST”) -> empty
System.EnvironmentVariable(“SERVER_NAME”) -> empty
etc…
I’m Using a Standard cgi …
ANy Hint ?

At the link above, you have this script which prints all environment variables :

[code]#!/usr/bin/perl

print "Content-type: text/html

";
print "Environment
";

foreach (sort keys %ENV) {
print "$: $ENV{$}

";
}

1;
[/code]

If it shows nothing, something is terribly wrong with your linux machine settings. If you are renting, contact support.

Otherwise, you will probably find much more help at the links below.

http://perlmonks.org/
http://perlguru.com/