PHP code example of dercoder / cloudflare

1. Go to this page and download the library: Download dercoder/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/ */

    

dercoder / cloudflare example snippets


    use Cloudflare\Zone\Dns;

    // Create a connection to the Cloudflare API which you can
    // then pass into other services, e.g. DNS, later on
    $client = new Cloudflare\Api('[email protected]', 'API_KEY');

    // Create a new DNS record
    $dns = new Cloudflare\Zone\Dns($client);
    $dns->create('12345678901234567890', 'A', 'name.com', '127.0.0.1', 120);

    use Cloudflare\Zone\Dns;

    // Create a connection to the Cloudflare API which you can
    // then pass into other services, e.g. DNS, later on
    $dns = new Cloudflare\Zone\Dns('[email protected]', 'API_KEY');
    $dns->create('12345678901234567890', 'TXT', 'name.com', '127.0.0.1', 120);

    use Cloudflare\Zone\Pagerules;

    // Define your targets
    // Currently you can only specify one URL per page rule but this implementation matches the API
    // so I am leaving it for now in the assumption they are planning to add multiple targets.
    $targets = [
        [
            'target' => 'url',
            'constraint' =>
            [
                'operator' => 'matches',
                'value' => 'http://example.co.uk/*'
            ]
        ]
    ];

    // Define your actions
    // Each action is held within it's own array.
    $actions = [
        [
            'id' => 'always_online',
            'value' => 'on'
        ]
    ];

    $pagerules = new Cloudflare\Zone\Pagerules('[email protected]', 'API_KEY');
    $pagerules->create($zoneId, $targets, $actions);