<?php 
// PHP CloudFlare IP Updater v4 
// When you need DDNS with CloudFlare.com 
// (c) 2018 anggit.com 
if (!(isset($_GET['user'], $_GET['pass']) 
    && $_GET['user'] === 'user' 
    && $_GET['pass'] === 'pass' 
    )) {         exit; 
    } 
$headers = array( 
    'X-Auth-Email: example@gmail.com', 
    'X-Auth-Key: 5d59f22ef88d9b6351d529e5c2c23156fdf3b, 
    'Content-Type: application/json' 
); 
$url  = 'https://api.cloudflare.com/client/v4/zones/504f0c70c8577b41c1d18bd0eff98a47/dns_records'; 
$host = 'homeserver.anggit.com'; 
// Stop edit if you are in doubt 
$ip = $_SERVER['REMOTE_ADDR']; 
if (file_exists('ip.txt')) {     if ($ip === file_get_contents('ip.txt')) { // IP address has not changed. No need to update :)         exit; 
    } 
    else {         file_put_contents('ip.txt', $ip);     } 
} 
else {     file_put_contents('ip.txt', $ip); } 
$ch = curl_init(); 
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); 
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); 
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); 
curl_setopt($ch, CURLOPT_TIMEOUT, 10); 
curl_setopt($ch, CURLOPT_URL, $url.'?name='.$host); 
$contents = curl_exec($ch); 
if (!empty($contents)) {     $data = json_decode($contents, true); 
    curl_setopt($ch, CURLOPT_URL, $url.'/'.$data['result'][0]['id']); 
    curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'PUT'); 
    $params = array( 
        'type' => 'A', 
        'name' => $host, 
        'content' => $ip, 
        'ttl' => 1, 
        'proxied' => false 
    ); 
    curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($params)); 
    curl_exec($ch); 
} 
curl_close($ch);