/    Sign up×
Community /Pin to ProfileBookmark

Getting A Visitor’s IP Address

Does anyone know a quick and easy way I can get a visitor’s IP address?

My utopia would be a simple call I could make from html or javascript to, say, php on the server which would then return a value into a JavaScript variable.

Note that I tried
<server>
var ip=request.ip
</server>

but a) I barely understand client-side javascript, so it’s fair to assume I got the server side code/syntax completely wrong
and b) I am not sure if my host provider allows me to run server-side java scripting.

Does anyone have a simple solution?

Thanks
IB
ps… vis-a-vis the posts today about doing a search before posting a question… on this, I’d love to, except that “ip” is less than the mandatory 4 characters.

to post a comment
JavaScript

7 Comments(s)

Copy linkTweet thisAlerts:
@sciguyryanOct 09.2003 — php version:

[code=php]<? echo $_SERVER['REMOTE_ADDR'] ?>[/code]

or the sort of JS version:

SCRIPT LANGUAGE="JAVASCRIPT" TYPE="TEXT/JAVASCRIPT">

<!--

var ip = '<!--#echo var="REMOTE_ADDR"-->';

window.alert("Your IP address is "+ip);

window.defaultStatus = "Your IP address is "+ip;

document.write("<TITLE>Your IP address is "+ip+"</TITLE>");

//-->

</SCRIPT>

i think those will work.
Copy linkTweet thisAlerts:
@chestertbauthorOct 09.2003 — Thanks Ryan,

The second JS code just returns

Your ip address is <!--#echo var="REMOTE_ADDR"-->, which is odd, because I seem to remember using that once before and it worked. Ah well... the PHP route is probably a better one.

How do I get a variable I can use in Javascript out of the PHP example?

Thanks

IB
Copy linkTweet thisAlerts:
@sciguyryanOct 09.2003 — i have no idea how to export variables from PHP into JS as my specialities lie in JSP, JS and VBScript - i can do it for them but, perhaps you should post that in the PHP forum?


hang on i remember a script that does some thing like that give me a minute>.......
Copy linkTweet thisAlerts:
@sciguyryanOct 09.2003 — <SCRIPT LANGUAGE="JavaScript" TYPE="text/javascript">

<!--

if ((navigator.appVersion.indexOf("4.") != -1) && (navigator.appName.indexOf("Netscape") != -1)){

ip = "" + java.net.InetAddress.getLocalHost().getHostAddress();

}

//-->

</script>

that stores the ip so you can use it.
Copy linkTweet thisAlerts:
@sciguyryanOct 09.2003 — <SCRIPT LANGUAGE="JavaScript" TYPE="text/javascript">

<!--

if ((navigator.appVersion.indexOf("4.") != -1) && (navigator.appName.indexOf("Netscape") != -1)){

ip = "" + java.net.InetAddress.getLocalHost().getHostAddress();

}

//-->

</script>

that stores the ip so you can use it but, it only works on netscape and if java is enabled - i will see if i can find a better one for you.
Copy linkTweet thisAlerts:
@Khalid_AliOct 09.2003 — the php code posted should work,you may need to change the html file extension to .php
Copy linkTweet thisAlerts:
@chestertbauthorOct 09.2003 — Thanks Ryan.

Really appreciate you taking the time to help.

Ian.
×

Success!

Help @chestertb spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.8,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...