runeveryday Posted August 31, 2011 Share Posted August 31, 2011 if ($conn = fsockopen ("whois.internic.net", 43)) { fputs($conn, $domain."\r\n"); while(!feof($conn)) { $output .= fgets($conn,128); } fclose($conn); what those code meaning? how to know what ther result of the $conn. thank you. the code is form http://www.codesphp.com/php-category/http/php-whois-query-function-to-query-some-nic-databases.html fputs($conn, $domain."\r\n"); why he write the $domain."\r\n" to $conn Quote Link to comment https://forums.phpfreaks.com/topic/246083-what-those-code-meaning/ Share on other sites More sharing options...
Adam Posted August 31, 2011 Share Posted August 31, 2011 The code within the link has a return statement which returns the response from the function. As for what that code is doing, it just opens a socket connection to "whois.internic.net" and writes the domain string (plus a carriage return and new line feed characters) to the stream. Once that data is written, the server at the other end detects the data is sent and responds. Quote Link to comment https://forums.phpfreaks.com/topic/246083-what-those-code-meaning/#findComment-1263851 Share on other sites More sharing options...
flappy_warbucks Posted August 31, 2011 Share Posted August 31, 2011 What Adam said. It looks like it is querying a whois database. Possibly for some sort of validation. (possibly to ensure the existance of a MX server or such) if ($conn = fsockopen ("whois.internic.net", 43)) // conditional statement. Attempts to open a socket to the server on port 43, and makes an instance of that connection in the var: $conn { fputs($conn, $domain."\r\n"); // sending data to the server $domain will be pre-assigned. the "\r\n" are new lines (carriage returns) while(!feof($conn)) // while there is still data, the loop will continue until it comes to EOF (end of file) { $output .= fgets($conn,128); // adds the data sent by the server to a string. } fclose($conn); // closes the connection. When the script reaches this point, the server has told us what it knows. And so it's good practice to close the connection to free resources. } Quote Link to comment https://forums.phpfreaks.com/topic/246083-what-those-code-meaning/#findComment-1263857 Share on other sites More sharing options...
runeveryday Posted September 1, 2011 Author Share Posted September 1, 2011 The code within the link has a return statement which returns the response from the function. As for what that code is doing, it just opens a socket connection to "whois.internic.net" and writes the domain string (plus a carriage return and new line feed characters) to the stream. Once that data is written, the server at the other end detects the data is sent and responds. what's the purpose of writes the domain string (plus a carriage return and new line feed characters) to the stream? thank you. Quote Link to comment https://forums.phpfreaks.com/topic/246083-what-those-code-meaning/#findComment-1264116 Share on other sites More sharing options...
runeveryday Posted September 1, 2011 Author Share Posted September 1, 2011 What Adam said. It looks like it is querying a whois database. Possibly for some sort of validation. (possibly to ensure the existance of a MX server or such) if ($conn = fsockopen ("whois.internic.net", 43)) // conditional statement. Attempts to open a socket to the server on port 43, and makes an instance of that connection in the var: $conn { fputs($conn, $domain."\r\n"); // sending data to the server $domain will be pre-assigned. the "\r\n" are new lines (carriage returns) while(!feof($conn)) // while there is still data, the loop will continue until it comes to EOF (end of file) { $output .= fgets($conn,128); // adds the data sent by the server to a string. } fclose($conn); // closes the connection. When the script reaches this point, the server has told us what it knows. And so it's good practice to close the connection to free resources. } many thanks. but there are some points i am still confused. 1, how do i know the port number is 43 2, what's the aim of writting the $domain to the $conn Quote Link to comment https://forums.phpfreaks.com/topic/246083-what-those-code-meaning/#findComment-1264118 Share on other sites More sharing options...
Adam Posted September 1, 2011 Share Posted September 1, 2011 http://www.pc-library.com/ports/tcp-udp-port/43/ You're sending data to that server, on port 43, via a socket connection. The fputs function simply handles writing data to that stream; which is the $conn resource. The server is listening for the request on that server, and once you write to it, it writes back a response which is collected using fgets. Quote Link to comment https://forums.phpfreaks.com/topic/246083-what-those-code-meaning/#findComment-1264281 Share on other sites More sharing options...
flappy_warbucks Posted September 1, 2011 Share Posted September 1, 2011 What Adam said. It looks like it is querying a whois database. Possibly for some sort of validation. (possibly to ensure the existance of a MX server or such) if ($conn = fsockopen ("whois.internic.net", 43)) // conditional statement. Attempts to open a socket to the server on port 43, and makes an instance of that connection in the var: $conn { fputs($conn, $domain."\r\n"); // sending data to the server $domain will be pre-assigned. the "\r\n" are new lines (carriage returns) while(!feof($conn)) // while there is still data, the loop will continue until it comes to EOF (end of file) { $output .= fgets($conn,128); // adds the data sent by the server to a string. } fclose($conn); // closes the connection. When the script reaches this point, the server has told us what it knows. And so it's good practice to close the connection to free resources. } many thanks. but there are some points i am still confused. 1, how do i know the port number is 43 2, what's the aim of writting the $domain to the $conn 1, how do i know the port number is 43 With this line: fsockopen ("whois.internic.net", 43) Let's break that down a tad. fsockopen is a a built in class that handles new server connections over a port that you tell it to. (http://uk2.php.net/fsockopen) "whois.internic.net" is the domain / ip-address that you want to connect to. (domain being what you type in the URL address bar in your browser. 43 is the port. A port is a virtual doorway to a computer server for data to travel. There is a comma between "whois.internic.net" and the 43. The reason for this is: you are giving the class another argument alongside the domain. 2, what's the aim of writting the $domain to the $conn $conn is a reference to a resource. You made that reference when opened the socket. $domain is the domain address you are sending to the whois. (it's called domain to make reading the script easier, for all intensive purposes you could have called it $x and it would have made no difference at all) Quote Link to comment https://forums.phpfreaks.com/topic/246083-what-those-code-meaning/#findComment-1264318 Share on other sites More sharing options...
Adam Posted September 3, 2011 Share Posted September 3, 2011 With all due respect "runeveryday", the PHP manual explains many of your answers. So would Google on the 'why port 43' question. Quote Link to comment https://forums.phpfreaks.com/topic/246083-what-those-code-meaning/#findComment-1264963 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.