cloudflare api srv添加php

时间:2015-07-19 15:00:00

标签: php api cloudflare srv

您好我正在尝试制作一个将SRV记录添加到cloudflare的脚本,但无法使其工作:(

<?php
include_once("includes/class_cloudflare.php");

$domain = 'game-panel.dk';
$type = 'SRV';
$name = 'testing';
$content = 'myip';
$ttl = '1';
$mode = '0';
$prio = '5';


$service = '_ts3';
$srvname = 'testing';
$protocol = 'UDP';
$weight = '1';
$port = '10002';
$target = 'testing.game-panel.dk';

$cf = new cloudflare_api("my@email.dk", "mycloudflareapikey");
$response = $cf->rec_new($domain, $type, $name, $content, $ttl, $mode, $prio);

print_r($response);
?>

我收到了这个回复:

stdClass Object ( [request] => stdClass Object ( [act] => rec_new ) [result] => error [msg] => Invalid service value. [err_code] => service- )

我使用这个类:

https://github.com/vexxhost/CloudFlare-API/blob/master/class_cloudflare.php

2 个答案:

答案 0 :(得分:1)

更新&amp;下面添加了完整功能代码:D

    <?php
    require_once($_SERVER["DOCUMENT_ROOT"]."/cloudflare/class_cloudflare.php");
    $cf = new cloudflare_api("E-Mail", "API Key");

    $domain = "domain.tld";
    $type = "SRV";
    $name = "ts3";
    $content = "1.1.1.1";
    $ttl = "1";
    $mode = "0";
    $prio = "5";


    $service = "_ts3";
    $srvname = "testing";
    $protocol = "_udp";
    $weight = "1";
    $port = "10002";
    $target = "test.domain.tld";

    // Add (SRV) AND (A) RECORD TO CLOUDFLARE.
    $response2 = $cf->rec_new($domain, $type, $name, $content, $ttl, $mode, $prio, $service, $srvname, $protocol, $weight, $port, $target);
    $response = $cf->rec_new($domain, 'A', $name, $content, $ttl, $mode, $service_mode = '1');  

    echo "<pre>";
    print_r($response);
    echo "</pre>";

    echo "<pre>";
    print_r($response2);
    echo "</pre>";  
?>

答案 1 :(得分:0)

  1. 您必须创建新区域并注册域名。
  2. 在步骤1之后,您可以创建dns记录...(尝试使用此https://github.com/Silent-Force/CloudFlare-API
  3. 您必须为请求指定正确的URL地址,然后选择Request方法。官方文档-https://api.cloudflare.com/