tomfmason Posted September 3, 2006 Share Posted September 3, 2006 Ok I have written a script that is supposed to retrieve a whois record from whois.net. Here is the code[code]<?php$url = "http://www.whois.net/whois.cgi2?d=";$domain = $_GET['domain'];$ch = curl_init();curl_setopt($ch, CURLOPT_URL, $url);curl_setopt($ch, CURLOPT_FAILONERROR, 1);curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);curl_setopt($ch, CURLOPT_TIMEOUT, 30);curl_setopt($ch, CURLOPT_POST, 1);curl_setopt($ch, CURLOPT_POSTFIELDS, "$domain");$result = curl_exec($ch);echo $result;?>[/code]I do not get any whois information back. When I look at the source This is all that I get.[code]<html><head><title>Whois.Net</title><META name="resource-type" content="document"><META name="keywords" content="domain names, domain name registration, custom domains, website hosting, custom URL , domain name application, new top level domains, toplevel, tld, gTLD, virtual, InterNIC, URL registration, web hosting service, TLD, registering, Internet addresses, available URL, InterNIC regulations, web addresses "><META name="distribution" content="global"></head><body bgcolor="#FFFFFF"><img src="images/top.gif" border=0 alt="Whois.Net"><br><br><form method=GET>Search WHOIS records: <input type=text maxlength=67 name="d"><input type=submit value="Submit"></form><center><table border=0 cellspacing=0 cellpadding=4 width="100%"> <tr> <td valign=top nowrap><font size=2> <font size=4 face=arial><b>Domain Registration</b></font><br> <a href="http://hosting.verio.com/index.php/dnr.html">Domain Pricing</a>, <a href="http://hosting.verio.com/index.php?SCREEN=ord[/code]Would it make a difference that the form method is get and not post? Any suggestions would be great.Thanks,Tom Link to comment https://forums.phpfreaks.com/topic/19598-retrieving-information-with-curl/ Share on other sites More sharing options...
Orio Posted September 3, 2006 Share Posted September 3, 2006 The form's method is GET. There's no need to use "CURLOPT_POSTFIELDS".Your code should be:[code]<?php$url = "http://www.whois.net/whois.cgi2?d=";$url.= urlencode($_GET['domain']);$ch = curl_init();curl_setopt($ch, CURLOPT_URL, $url);curl_setopt($ch, CURLOPT_FAILONERROR, 1);curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);curl_setopt($ch, CURLOPT_TIMEOUT, 30);$result = curl_exec($ch);curl_close();echo $result;?>[/code]Orio. Link to comment https://forums.phpfreaks.com/topic/19598-retrieving-information-with-curl/#findComment-85269 Share on other sites More sharing options...
tomfmason Posted September 3, 2006 Author Share Posted September 3, 2006 Thanks. That was the problem. Here is the fix.[code]<?php$domain = $_GET['domain'];if (!$domain) { echo "You did not enter a domain. Please try again."; exit();}$url = 'http://www.whois.net/whois.cgi2?d=' . $domain;$ch = curl_init();curl_setopt($ch, CURLOPT_URL, $url);curl_setopt($ch, CURLOPT_FAILONERROR, 1);curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);curl_setopt($ch, CURLOPT_TIMEOUT, 30);$result = curl_exec($ch);curl_close();echo $result;?>[/code]Thanks again,Tom Link to comment https://forums.phpfreaks.com/topic/19598-retrieving-information-with-curl/#findComment-85272 Share on other sites More sharing options...
Orio Posted September 3, 2006 Share Posted September 3, 2006 That looks find to me :) Are you getting some error or something?I would change the validation of $domain to:[code]<?phpif (!isset($_GET['domain']) || empty($_GET['domain'])) { echo "You did not enter a domain. Please try again."; exit();}$url = 'http://www.whois.net/whois.cgi2?d='.urlencode(trim($_GET['domain']));//rest of code?>[/code]Orio. Link to comment https://forums.phpfreaks.com/topic/19598-retrieving-information-with-curl/#findComment-85279 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.