A small, compact but flexible API library for popular CDN provider CloudFlare written in PHP.
Supports both HOST and CLIENT APIs.
CloudFlare Client API documentation
CloudFlare Hosting Provider API documentation
- Get yourself an API key. You can grab one here.
- Replace {EMAIL} and {TOKEN} with your real data.
- Start coding.
You can find some demo code in /examples dir.
But still, here are the basics:
If you want to use CLIENT API then instantiate API object like this:
$cf_api_client = new CF("{EMAIL}","{TOKEN}");
Otherwise just pass your {HOST_KEY} to the constructor:
$cf_api_client = new CF("{HOST_KEY}");
And start making requests:
$response = $cf_api_client->rec_new(array(
'z' => 'yoursite.com',
'name' => 'new.yoursite.com',
'ttl' => 1,
'type' => 'A',
'content' => '1.2.3.4'
));
Note: rec_new
is a name of api method listed in docs
Also, you can change your current EMAIL/TOKEN/HOST_KEY values at any time without re-creating the object:
$cf_api_client->setEmail($email);
$cf_api_client->setToken($token);
$cf_api_client->setHostKey($host_key);
You can install cloudflare-api
via Composer:
composer require okwinza/cloudflare-api
Or by simple require
.
vk: okwinza
email: okwinza@gmail.com