This shows you the differences between two versions of the page.
hand-made-code [2014/09/10 21:22] |
hand-made-code [2014/09/10 21:22] (current) |
||
---|---|---|---|
Line 1: | Line 1: | ||
+ | finger.html | ||
+ | |||
+ | <code> | ||
+ | <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" | ||
+ | "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> | ||
+ | <html xmlns="http://www.w3.org/1999/xhtml"> | ||
+ | <head> | ||
+ | <title>Registration</title> | ||
+ | <script type="text/javascript" language="javascript"> | ||
+ | // <![CDATA[ | ||
+ | |||
+ | // Need to make an object of XMLHttpRequest Type. | ||
+ | function createRequestObject() { | ||
+ | var ro; | ||
+ | if (navigator.appName == "Microsoft Internet Explorer") { | ||
+ | ro = new ActiveXObject("Microsoft.XMLHTTP"); | ||
+ | } else { | ||
+ | ro = new XMLHttpRequest(); | ||
+ | } | ||
+ | return ro; | ||
+ | } | ||
+ | var http = createRequestObject(); | ||
+ | |||
+ | // Function that calls the PHP script: | ||
+ | function sendRequest(domainname) { | ||
+ | // Call the script. | ||
+ | // Use the GET method. | ||
+ | // Pass the email address in the URL. | ||
+ | http.open('get', 'finger.php?domain=' + encodeURIComponent(domainname)); | ||
+ | http.onreadystatechange = handleResponse; | ||
+ | http.send(null); | ||
+ | } | ||
+ | |||
+ | // Function handles the response from the PHP script. | ||
+ | function handleResponse() { | ||
+ | // If everything's okay: | ||
+ | if(http.readyState == 4){ | ||
+ | // Assign the returned value to the document object. | ||
+ | document.getElementById('domain_label').innerHTML = http.responseText; | ||
+ | } | ||
+ | } | ||
+ | // ]]> | ||
+ | </script> | ||
+ | </head> | ||
+ | <body> | ||
+ | <form action="finger.php" method="post"> | ||
+ | Domain: <input name="domainname" type="text" size="30" maxlength="60" | ||
+ | onkeyup="sendRequest(this.form.domainname.value)" /> <span id="domain_label"></span><br /> | ||
+ | </form> | ||
+ | </body> | ||
+ | </html> | ||
+ | </code> | ||
+ | |||
+ | finder.php | ||
+ | <code> | ||
+ | <?php | ||
+ | |||
+ | $pdolist = array('at', 'co.at', 'or.at'); | ||
+ | |||
+ | if (isset($_GET['domain'])) { | ||
+ | foreach ($pdolist as $pdo) { | ||
+ | $domain = $_GET['domain'].'.'.$pdo; | ||
+ | $r = finger($domain); | ||
+ | $text = ( $r == 0 ) ? "occupied" : "free" ; | ||
+ | printf("<br> %s [%s]", $domain, $text); | ||
+ | } | ||
+ | } | ||
+ | |||
+ | function finger($domain) { | ||
+ | $fp = fsockopen('finger.nic.at', 79); | ||
+ | $domain .= "\n"; | ||
+ | fputs($fp, $domain, strlen($domain)); | ||
+ | $text = fgets($fp); | ||
+ | fclose($fp); | ||
+ | if (preg_match ('/NO domain data/', $text)) { | ||
+ | return 1; | ||
+ | } else { | ||
+ | return 0; | ||
+ | } | ||
+ | } | ||
+ | ?> | ||
+ | </code> | ||
+ | |||