title: php api integration for reseller club
body: <p>i need to implement reseller api to my website to search available domain name, i have reseller id and key, so i used the below code</p>
  
  <pre><code>&lt;html&gt;
  &lt;head&gt;
  &lt;/head&gt;
  &lt;body&gt;
  &lt;form method="post" action="test.php"&gt;
      &lt;input type="text" name="domain" value="&lt;?php echo $domainname; ?&gt;"/&gt;
  
      &lt;input type="checkbox" name="tld[]" value="com"  &lt;?php  if(!isset($_POST['check'])){  ?&gt; checked="checked" &lt;?php } elseif (in_array("com", $tldarray)) {  ?&gt; checked="checked" &lt;?php  } ?&gt; /&gt;com
      &lt;input type="checkbox" name="tld[]" value="net" &lt;?php if (in_array("net", $tldarray)) {  ?&gt; checked="checked" &lt;?php  } ?&gt; /&gt;net
      &lt;input type="checkbox" name="tld[]" value="in" &lt;?php if (in_array("in", $tldarray)) {  ?&gt; checked="checked" &lt;?php  } ?&gt; /&gt;in
      &lt;input type="checkbox" name="tld[]" value="biz" &lt;?php if (in_array("biz", $tldarray)) {  ?&gt; checked="checked" &lt;?php  } ?&gt; /&gt;biz
      &lt;input type="checkbox" name="tld[]" value="org" &lt;?php if (in_array("org", $tldarray)) {  ?&gt; checked="checked" &lt;?php  } ?&gt; /&gt;org
      &lt;input type="checkbox" name="tld[]" value="asia" &lt;?php if (in_array("asia", $tldarray)) {  ?&gt; checked="checked" &lt;?php  } ?&gt; /&gt;asia
  
  
      &lt;input type="submit" name="check" value="Check"/&gt;
  &lt;/form&gt; 
  &lt;/body&gt;
  &lt;/html&gt; 
  </code></pre>
  
  <p>and here comes my php,</p>
  
  <pre><code>&lt;?php
  
  $api_user_id="xxx";
  $api_key="yyyyyy";
  
  
  function domainCallAPI($method, $url, $data = false) {
      $curl = curl_init();
  
      switch ($method) {
          case "POST":
              curl_setopt($curl, CURLOPT_POST, 1);
  
              if ($data)
                  curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
              break;
          case "PUT":
              curl_setopt($curl, CURLOPT_PUT, 1);
              break;
          default:
              if ($data)
                  $url = sprintf("%s?%s", $url, http_build_query($data));
      }
  
      // Optional Authentication: - Need not touch this
      curl_setopt($curl, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
      curl_setopt($curl, CURLOPT_USERPWD, "username:password");
      curl_setopt($curl, CURLOPT_URL, $url);
      curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
      return curl_exec($curl);
  }
  ?&gt;
  
  &lt;?php
  //Example Call to see available domains and suggestions
  $url = '';
  $tldarray[] = "";
  $domainname="";
  if (isset($_POST['check']) &amp;&amp; isset($_POST['domain']) &amp;&amp; $_POST['domain'] != "" &amp;&amp; isset($_POST['tld']) &amp;&amp; $_POST['tld'] != "") {
  
      $domainname = $_POST['domain'];
      $tld = "";
      $i = 0;
      foreach ($_POST['tld'] as $arrayitem) {
          $tld.='&amp;tlds=' . $arrayitem;
          $tldarray[$i] = $arrayitem;
          $i++;
      }
  
      $url = 'https://test.httpapi.com/api/domains/available.json?auth-userid=' . $api_user_id . '&amp;auth-password=' . $api_key . '&amp;domain-name=' . $domainname . $tld . '&amp;suggest-alternative=true';
      $data = "";
      $data = domainCallAPI('GET', $url, $data);
      $datajson = json_decode($data, TRUE);
      $fulldomainname = "";
      //  $flag=0;
      foreach ($tldarray as $arrayitem) {
  
          $fulldomainname = $domainname . "." . $arrayitem;
          echo '&lt;br/&gt;' . $fulldomainname;
          if ($datajson[$fulldomainname]["status"] == "available") {
              echo '    Available';
              // $flag=1;
          } else {
              echo '    Not Available &lt;br/&gt;';
          }
      }
      // Domain Suggestions
      $stack = array("");
      $i = 0;
      foreach ($datajson[$domainname] as $sugdomain =&gt; $sugtld) {
          // echo $sugdomain.'.'.$tld;
  
          $stack[$i] = $sugdomain;
          $i++;
      }
      echo '&lt;br/&gt;Sugg names : &lt;br/&gt;';
      $i = 0;
      foreach ($stack as $value) {
          foreach ($datajson[$domainname][$value] as $sugdomain =&gt; $sugtld) {
              if ($datajson[$domainname][$value][$sugdomain] == "available") {
                  echo $value . '.' . $sugdomain;
                  echo '&lt;br/&gt;';
                  $i++;
                  if ($i == 7) {
  
                      break;
                  }
              }
          }
  
          if ($i == 7) {
  
              break;
          }
      }
      // domain suggestions end
  }
   elseif (isset($_POST['check'])){
  
      if(!isset($_POST['tld'])){
        echo '&lt;br/&gt; Tick Your Domain';
  
      }
       if( !isset($_POST['domain']) || $_POST['domain'] =="" ){
          echo '&lt;br/&gt; Type Domain Name';     
      }else{
          $domainname=$_POST['domain'];
      }
  }
  ?&gt;
  </code></pre>
  
  <p>it always show result as api not available, i am not familiar with either php or api i just found this code on net and used, help me on this please. </p>
  
  <p>i need reseller api only since i have been doing business using reseller club,...</p>
  
  <p>all i need is just domain name search using reseller api. thank you.</p>