Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Client IP Address Detection

Status
Not open for further replies.

vikramonline

Programmer
Oct 14, 2003
186
IN
This script does not work for me.

<SCRIPT LANGUAGE="JavaScript">
var ip = '<!--#echo var="REMOTE_ADDR"-->';
// This part is for an alert box
alert("Your IP address is "+ip);
// This part is for the status bar
window.defaultStatus = "Your IP address is "+ip;
// This part is for the title bar
document.write("<title>Your IP address is "+ip+"</title>");
</script>

I got this script from a site.

"Depending on your server set-up,you may need to use the ".shtml" extension [instead of the "html" or "htm"] as the script uses Server Side Includes."

was mentioned along with the script.I am using IIS Server and when I put this script in an htm or html page , it does not work.

Please suggest
 
Try changing the extension of the filename to .asp (example: testpage.asp). This will tell IIS that it is to parse the contents of the .asp file and process any server-side directives before delivering the complete HTML to the client browser.

Jeff
 
It does not work either

Help us to answer your questions by posting useful feedback on the suggestions put forward. Without any feedback from you... you will not get any feedback from us.

My question to you...

When you say "it does not work" what do you mean? What are you expecting? Does the page load? Is the code you posted above the "view source" or the actual "source file" (as lives on the IIS server)? Does anything else on the page work (maybe there is a Javascript problem somewhere)?

Whilst I try... I can't read minds :)

Jeff

PS: That's BabyJeffy... s!=f... and where I come from... a Jessy is considered an insult... please don't insult me.
 
your suppost to upload it as an htm or html file first and then once on the server you then change it to .shtml...

__________________________________________________________
"The only difference between me and a mad man is that I'm not mad."
- Dali
 
BabyJeffy,


When I try to run this in a htm or asp file what I get in the alert box is not the IP Address but the string "<!--#echo var="REMOTE_ADDR"-->" itself.


Everything else works very fine.
 
Now I allowed the Server Side Includes on my IIS Server,but what I get is the local IP Address and the same local IP Address is displayed no matter from where I access the page.
 
Try with ASP and:
Code:
var ip = '<% = Request.ServerVariables("REMOTE_ADDR" ) %>';
 
Vongrunt,

I am actually using ASP ,I have already tried "REMOTE_ADDR" but what I get is not the client IP but my local IP.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top