Forum Moderators: open

Message Too Old, No Replies

Running functions based on IP address

Functions only want to run for visitors, not internal views.

         

ritch_b

4:17 pm on Nov 10, 2003 (gmt 0)

10+ Year Member



I currently have a simple piece of JavaScript that does a couple of document.writes to add a few links to a common navigation page.

Ideally though, I'd like a piece of JavaScript that does different document.writes based upon the IP address.

If the hostaddress is 192.168.anything, function a should be called. Any other hostaddress and function b should be called. Function a would display links for internal use only, whilst function b would display links for normal visitors from outside of our network.

I've found a couple of pieces of JavaScript that can do similar things based upon the referring domain name, but nothing that suits this particular application.

Any suggestions would be appreciated as a starter for six.

R.

DrDoc

4:27 pm on Nov 10, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



This thread will provide some help: [webmasterworld.com...]

Basically, something like this would work:

<script language="javascript">
var ip = '<!--#echo var="REMOTE_ADDR"-->'
var regExp = /^192\.168\.\d{1,3}\.\d{1,3}$/
if(regExp.test(ip)) {
local IP
}
else {
other IP
}
</script>

ritch_b

4:33 pm on Nov 10, 2003 (gmt 0)

10+ Year Member



As ever, couldn't see for looking.

Cheers DrDoc!

R.