Skip to content

Instantly share code, notes, and snippets.

@hasangilak
Last active January 27, 2017 08:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hasangilak/d4349d3a97ddcdfc846b98228383e6fb to your computer and use it in GitHub Desktop.
Save hasangilak/d4349d3a97ddcdfc846b98228383e6fb to your computer and use it in GitHub Desktop.
a php cloudflare client for adding subdomain. depends on guzzle >= v6
<?php
namespace App\Services\CloudFlare;
use GuzzleHttp\Client;
class CloudFlareClient
{
private $email;
private $key;
private $zone;
public function __construct($email, $key, $zone)
{
$this->email = $email;
$this->key = $key;
$this->zone = $zone;
}
public function listAllZones()
{
$client = new Client();
$url = 'https://api.cloudflare.com/client/v4/zones';
$parameters = [
'headers' => [
'X-Auth-Email' => $this->email,
'X-Auth-Key' => $this->key,
'Content-Type' => 'application/json'
]
];
return $client->get($url, $parameters);
}
public function addSubDomain($name, $ip)
{
$client = new Client();
$response = $client->request('POST',
'https://api.cloudflare.com/client/v4/zones/' . $this->zone . '/dns_records', [
'json' => [
'name' => $name,
'type' => 'A',
'content' => $ip,
'proxied' => true
],
'headers' => [
'X-Auth-Email' => $this->email,
'X-Auth-Key' => $this->key,
'Content-Type' => 'application/json'
]
]);
return $response;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment