Javascript environment variables demo

This Javascript on the client side:

<SCRIPT LANGUAGE="javascript">
var server    = window.location.hostname;
var lastmod   = document.lastModified;   
var referrer  = document.referrer;   
var browser   = navigator.appName;
var os        = navigator.platform;
var useragent = navigator.userAgent;
var today     = new Date();
var r         = Math.floor ( Math.random() * 10000000 );
document.write("Server: "+server+" <br>");
document.write("This page last modified: "+lastmod+" <br>");
document.write("Referring page: <a href="+referrer+">"+referrer+"</a> <p>");
document.write("Browser: "+browser+" <br>");
document.write("OS: "+os+" <br>");
document.write("User agent string: "+useragent+" <p>");
document.write("Date: "+today.toString()+" <br>");
document.write("Random number from 0 to 10,000,000: "+r+" <p>");


Javascript and SSI (client and server)

We can use SSI to access environment variables on the server, before this is sent to the client.
This is useful to get client IP, which Javascript cannot access.

The following code is sent to the client with the environment variables already hard-coded.
(View Source to see that.)

This Javascript:

<SCRIPT LANGUAGE="javascript">
var servername = '<!--#echo var="SERVER_NAME"-->';
var serverip   = '<!--#echo var="SERVER_ADDR"-->';
var clientip   = '<!--#echo var="REMOTE_ADDR"-->';
var clientname = '<!--#echo var="REMOTE_HOST"-->';
var clientip2  = '<!--#echo var="HTTP_X_FORWARDED_FOR"-->';
var lastmod    = '<!--#echo var="LAST_MODIFIED"-->';
var referrer   = '<!--#echo var="HTTP_REFERER"-->';
var useragent  = '<!--#echo var="HTTP_USER_AGENT"-->';
document.write("Server name: "+servername+" <br>");
document.write("Server IP: "+serverip+" <p>");
document.write("Client IP: <a href="+clientip+">"+clientip+"</a> <br>");
document.write("Client name: <a href="+clientname+">"+clientname+"</a> <br>");
document.write("Client original IP: <a href="+clientip2+">"+clientip2+"</a> <p>");
document.write("This page last modified: "+lastmod+" <br>");
document.write("Referring page: <a href="+referrer+">"+referrer+"</a> <br>");
document.write("User agent string: "+useragent+" <p>");