Meniu

How To Perform HTTP-GET via Curl Commands inside PHP

PHP supports libcurl that allows you to connect and communicate to many different types of servers with many different types of protocols.

libcurl currently supports the http, https, ftp, gopher, telnet, dict, file, and ldap protocols. libcurl also supports HTTPS certificates, HTTP POST, HTTP PUT, FTP uploading, HTTP form based upload, proxies, cookies, and user+password authentication.

Here's a quick scan of how I just wasted several days and couple of hours trying to integrate simple PHP curl codes with existing API backends from Enom and Namecheap. Currently Namecheap does not have publicly available integration interface that is as simple as 1-2-3 site installation.

Now the fun begins.

$url = 'API server host';
$curl;
$curl = curl_init();
curl_setopt($curl, CURLOPT_CONNECTTIMEOUT, 2);
curl_setopt($curl, CURLOPT_HEADER, false);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
curl_setopt($curl, CURLOPT_URL, $url);
$result = curl_exec($curl);
curl_close($curl);
header('Content-Type: application/xml; charset=ISO-8859-1');
print $result;


By default, curl makes use of HTTP-GET unless explicitly specified to be false and as HTTP-POST method.

This PHP codes simply checks a specified particular domain TLD via PHP form, for the possibiblity of domain existence. That's it. As we all know, the free WHOIS and DOMAINTOOLS servers are limited by request for security reason, that is why this code has been created for some time. Note that the return results from Namecheap API server https://api.sandbox.namecheap.com comes in XML format.

Probability is, this is the same approach that has been utilized for desktop and web applications like twitter, entrecard, myblog, and even YMail and GMail - the difference is that the front-end differs, where a few of them enjoyed more of AJAX and SOAP. :) The rest are PHPs.

Furthermore, these codes can also be expanded to actually register domains, and even have a full-pledged DNS control and management system acting as domain registrar platform, like Godaddy, Namecheap, Onlinenic and Enoms.

Mirela

Zona de mobile
  • | 34 articole

Nici un comentariu inca. Fii primul!
  • powered by Verysign