Jump to content


Photo

retrieving information with curl


  • Please log in to reply
3 replies to this topic

#1 tomfmason

tomfmason
  • Staff Alumni
  • Advanced Member
  • 1,696 posts
  • Locationstealing your wifi

Posted 03 September 2006 - 06:22 PM

Ok I have written a script that is supposed to retrieve a whois record from whois.net. Here is the 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;
?>

I do not get any whois information back. When I look at the source This is all that I get.

<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

Would it make a difference that the form method is get and not post? Any suggestions would be great.

Thanks,
Tom

Traveling East in search of instruction, and West to propagate the knowledge I have had gained.

current projects: pokersource

My Blog | My Pastebin | PHP Validation class | Backtrack linux


#2 Orio

Orio
  • Staff Alumni
  • Advanced Member
  • 2,491 posts

Posted 03 September 2006 - 06:36 PM

The form's method is GET. There's no need to use "CURLOPT_POSTFIELDS".
Your code should be:
<?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;
?>

Orio.
Think you're smarty?

(Gone until 20 to November)

#3 tomfmason

tomfmason
  • Staff Alumni
  • Advanced Member
  • 1,696 posts
  • Locationstealing your wifi

Posted 03 September 2006 - 06:43 PM

Thanks. That was the problem.  Here is the fix.

<?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;
?>

Thanks again,
Tom

Traveling East in search of instruction, and West to propagate the knowledge I have had gained.

current projects: pokersource

My Blog | My Pastebin | PHP Validation class | Backtrack linux


#4 Orio

Orio
  • Staff Alumni
  • Advanced Member
  • 2,491 posts

Posted 03 September 2006 - 07:05 PM

That looks find to me :) Are you getting some error or something?

I would change the validation of $domain to:
<?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

?>

Orio.
Think you're smarty?

(Gone until 20 to November)




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users