Saturday, June 20, 2009

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.

For the docs.

6 comments:

ankara hali yikama said...

nice blog nice blog

stus oldrecordsrust said...

Hello I ran into your BLOGspot after looking UP on Internet about Fedora 8 tips (k9Copy) .

Iam using Fedora 8 on my Desktop -with a Dual boot situation with Windows xp (2 harddrives) .

I was wondering if anyone here has installed TRANSCODE onto fedora 8 Successfully???

Regards -stuart smith

stus oldrecordsrust said...

Hello thank you for letting me login .

Wiil be back in touch.

thanks -stuart smith

VeRTiTO said...


For Transcode, use rpmfusion-free repo

source - https://bitbucket.org/france/transcode-tcforge/downloads

stus oldrecordsrust said...

Ok - thanks for the website linkage --but that bitbucket site has only Tar.gz type files NOT rpms,!!!

stus oldrecordsrust said...

Ihave to go to LinuX schoolanf learnhow to do Tarball installation --or just pay some Tech to do it for me!!!

Sign up for PayPal and start accepting credit card payments instantly.
ILoveTux - howtos and news | About | Contact | TOS | Policy