Home Articles FAQs XREF Games Software Instant Books About Feedback Search Site-Map
irt.org logo

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

irt.org | Knowledge Base | JavaScript | Referrer | Q352 [ previous next ]

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

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>

Provide feedback ...
AddThis Social Bookmark Button

Provide feedback ... AddThis Social Bookmark Button


Last Updated: 6th July 2009. Maintained by: Martin Webb and Michel Plungjan
irt.org liability, trademark, document use, privacy statement and software licensing rules apply.
Copyright © 1996-2009 irt.org, All Rights Reserved.