PHP code example of reolservices / cloudflare

1. Go to this page and download the library: Download reolservices/cloudflare library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

reolservices / cloudflare example snippets


    "    ...
        "reolservices/cloudflare": "*",
        ...
    }


$config = [
    ...
    'params' => [
        ...
        'cloudflare' => [
            "cloudflare_auth_email" => "[email protected]",
            "cloudflare_auth_key" => "YOUR_AUTH_KEY_HERE",
        ],
        ...
    ],
    ...
];

    // Initialize the client
    $cfClient = new \Cloudflare\Client();

    // Retrieve the lise of all DNS records for a given domain that is registered in your Cloudflare account
    $domains = $cfClient->getDNSRecords('example.com');

    // Retrieve the list of 'A' records for a given subdomain
    $subDomains = $cfClient->getDNSRecords('sub.example.com', 'A');

    // Add a new Subdomain (A record) to your Cloudflare DNS records
    $newDomain = $cfClient->addDNSRecord('new.sub.example.com', '1.2.3.4');

    // Add a new CNAME / MX record to your Cloudflare DNS records
    $newCNAME = $cfClient->addDNSRecord('other.sub.example.com', 'new.sub.example.com', 'CNAME');
    $newMX = $cfClient->addDNSRecord('new.sub.example.com', '1.2.3.4', 'MX');

    // Remove an MX DNS record from your DNS records for a given (sub)domain
    $deleteMX = $cfClient->deleteDNSRecords('new.sub.example.com', 'MX');

    // Remove all DNS records for a given (sub)domain
    // This is not allowed on top level domains for security reasons
    // if you want to do it anyway, please connect to your Cloudflare console
    $deleteDomain = $cfClient->deleteDNSRecords('sub.example.com');