PDA

View Full Version : environmental variables in javascript


kfenstad
11-12-2002, 03:25 PM
Could someone tell us how to get the variables server and ip from javascript?
This is what we have so far but it doesn't work...
W+="&server="+escape(SERVER);
W+="&ip="+escape(REMOTE_ADDR);

thanks.

beetle
11-12-2002, 03:33 PM
That subject covered here (http://www.codingforums.com/showthread.php?s=&threadid=9271&highlight=remoteaddr).

Please try a search next time :D

kfenstad
11-12-2002, 04:00 PM
Okay... we are calling a php script with javascript and giving it this var W to parse. like so...

var W="http://server.com/var.php?";
W+="&server=server"//+escape(SERVER);
W+="&ip="+escape(REMOTE_ADDR);
W+="&order=order"//+escape(ORDER);
W+="&browserDate="+escape(new Date());
W+="&title="+escape(document.title);
W+="&url="+window.document.URL;
document.write("<IMG BORDER=0 WIDTH=1 HEIGHT=1 SRC=" + (W) + ">")

So how could we do this without using Javascript to get server and ip?

beetle
11-12-2002, 04:20 PM
Well, this could be laid out any number of ways, but here's an option...<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Blah</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<script type="text/javascript">
var ip = escape("<!--#echo var="REMOTE_ADDR"-->");
var server = escape("<!--#echo var="SERVER"-->");
var order = escape("<!--#echo var="ORDER"-->");
</script>
</head>

<body>
<script type="text/javascript">
var W="http://server.com/var.php?";
W+="&server="+server;
W+="&ip="+ip;
W+="&order="+order;
W+="&browserDate="+escape(new Date());
W+="&title="+escape(document.title);
W+="&url="+window.document.URL;
alert(W);
document.write('<img border="0" width="1" height="1" src="' + W + '">')
</script>
</body>
</html>

glenngv
11-13-2002, 06:50 AM
since you are not assigning an image in the img src attribute, that will display a broken image in the page. to avoid that, you should change this:

document.write('<img border="0" width="1" height="1" src="' + W + '">')

to this:

var php = new Image();
php.src = W;