Jump to content

Archived

This topic is now archived and is closed to further replies.

tomfmason

retrieving information with curl

Recommended Posts

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: &nbsp; <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>,&nbsp;
    <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

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
That looks find to me :) Are you getting some error or something?

I would change the validation of $domain to:
[code]<?php

if (!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.

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.