Skip to content

Instantly share code, notes, and snippets.

@KingPin
Forked from gentlecat/cloudflare.php
Last active January 2, 2016 23:59
Show Gist options
  • Save KingPin/8379743 to your computer and use it in GitHub Desktop.
Save KingPin/8379743 to your computer and use it in GitHub Desktop.
<?php
/**
* DDNS Service: Custom
* DYNDNS Server: <yourserver.com>
* Username:
* Password:
* Host Name:
* URL: /cloudflare_update.php?key=&hostname=
*/
/**
* Settings
*/
define('API_KEY', $_GET['apikey']); // CloudFlare API key
define('USERNAME', 'user@example.com'); // Email address used to login into CloudFlare
define('IP', getCurrentIP()); // Current IP address
echo 'Setting IP address to "' . IP . '"...<br />';
// Your web sites:
update('example.com');
update('example.net');
/**
* @return string Current IP address
*/
function getCurrentIP()
{
$source = "http://api.externalip.net/ip/";
return file_get_contents($source);
}
/**
* This function sends request to CloudFlare to change IP address of an A record with specific name
* @param $hostname Name of the record that needs to be updated
*/
function update($hostname)
{
echo "<br />Updating $hostname...<br />";
$update_url = 'https://www.cloudflare.com/api_json.html?a=DIUP&hosts='
. $hostname . '&u=' . USERNAME . '&tkn=' . API_KEY . '&ip=' . IP;
echo file_get_contents($update_url);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment