Create a domain search engine
This small PHP code example shows you how it is simple to use our XML API in your own code.
<?php //This is an example on how to integrate a domain search engine in its own website //Define your include directory $dir=""; require_once($dir."xmlrpc.inc"); //We use the Gandi OT&E url $proxy = new xmlrpc_client("https://api.ote.gandi.net/xmlrpc/"); //This is the login part, don't forget to use your own login / password (received by email once the Test API activated) $msg = new xmlrpcmsg("login",array(new xmlrpcval("XXX-GANDI"),new xmlrpcval("XXXXX"))); $reply = $proxy->send($msg); if ($reply->faultCode()) { echo "couldn't login because: " . $reply->faultString() . "\n"; exit(67); } //We store the login session to use it in following methods $session = $reply->value(); //Let's get the domain extension list managable via the API //Tlds available on the OT&E differs from the one available in production: //Note this could differ from the list available on Gandi.net $msg = new xmlrpcmsg("tld_list", array($session)); $reply = $proxy->send($msg); if ($reply->faultCode()) { printf("could not retrieve the TLD list because: %s\n", $reply->faultString()); } else { $tlds = php_xmlrpc_decode($reply->value()); } //We can now display the search form echo " <html> <body> <div align='center'> <form method='POST' action='$PHP_SELF'> Name to search <input name='word' type='text' value='$_POST[word]' size='20'> <br /> "; // We display now tlds for($i=1;$i<sizeof($tlds);$i++) { echo "<input type='checkbox' name=checkedtld[] value='$tlds[$i]' "; if(in_array($tlds[$i],$checkedtld)==1) echo "checked"; echo ">$tlds[$i]"; if(fmod($i,5)==0) echo "<br/>"; } //We manage the result of the form and we display it if($_POST[submit]) { for($i=0;$i<sizeof($_POST[checkedtld]);$i++) $domains[]=new xmlrpcval($_POST[word].".".$_POST[checkedtld][$i]); $msg = new xmlrpcmsg("domain_available", array($session, new xmlrpcval($domains, "array"))); $reply = $proxy->send($msg); if ($reply->faultCode()) { printf("couldn't check for availability because: %s\n", $reply->faultString()); } else { $val = $reply->value(); $val->structreset(); echo "<br/>"; while (list($key, $value) = $val->structeach()) { printf("%s : %s\n", $key, $value->scalarval() ? "<font color=green>Available</font> <a href='https://www.gandi.net/whois/details?search=$key' target='_blank'>Buy it now !</a>" : "<font color=red>Not Available</font>"); echo "<br/>"; } } } echo " <br/> <input type='submit' name='submit' value='submit'> </form> </body> </html> "; ?>
Dernière modification: le 26/09/2014 à 15:50 par Ryan A. (Gandi)