Jump to content

retrieving information with curl


tomfmason

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.