Home Articles FAQs XREF Games Software Instant Books BBS About FOLDOC RFCs Feedback Sitemap
irt.Org
#

Q352 How can I detect and verify the domain name that someone has used to access my site?

You are here: irt.org | FAQ | JavaScript | Referrer | Q352 [ previous next ]

This is better done using a CGI script that checks the REMOTE_HOST and/or the REMOTE_ADDR environment variables.

However, if you've not got access to the CGI-BIN then on the client side you can use several of the Java-JavaScript solutions:

<SCRIPT LANGUAGE="JavaScript"><!--
netscapeTest = parseInt(navigator.appVersion)
explorerTest = navigator.appName.indexOf("Microsoft") + 1

function netscapeThree() {
     if (navigator.javaEnabled()) {
          userDomain = java.net.InetAddress.getLocalHostName()
          return (userDomain.toString())
     } else {
          return null
     }
}

function netscapeFour() {
     if (navigator.javaEnabled()) {
          baseAddress = java.net.InetAddress.getLocalHost()
          userDomain = baseAddress.getHostName()
          return (userDomain.toString())
     } else {
          return null
     }
}

if ((explorerTest == "0") && (netscapeTest == "3")) {
     domainName = netscapeThree()
} else if ((explorerTest == "0") && (netscapeTest == "4")) {
     domainName = netscapeFour()
} else {
     domainName = "null"
}

if (domainName == 'xx.yy.zz.com')
    alert('domain name is valid');
else
    alert('domain name ' + domainName + ' is invalid');
//--></SCRIPT>

©2018 Martin Webb