Last active
August 29, 2015 14:06
-
-
Save jerry74/fe657519f7f9620a804a to your computer and use it in GitHub Desktop.
Cloudflare DDNS
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| if( empty($_GET['key']) || $_GET['key'] != "Pv226Key" ) die("Not Authorized!"); | |
| $allips = array(); | |
| if (isset($_SERVER['HTTP_CLIENT_IP'])) { | |
| array_push($allips, $_SERVER['HTTP_CLIENT_IP']); | |
| } | |
| if (isset($_SERVER['HTTP_X_FORWARDED_FOR'])) { | |
| $proxyips = explode(',', $_SERVER['HTTP_X_FORWARDED_FOR']); | |
| $allips = array_merge($allips, $proxyips); | |
| } | |
| if (isset($_SERVER['HTTP_X_REMOTE_ADDR'])) { | |
| array_push($allips, $_SERVER['HTTP_X_REMOTE_ADDR']); | |
| } | |
| array_push($allips, $_SERVER['REMOTE_ADDR']); | |
| function findip($allips) { | |
| foreach($allips as $ip) { | |
| $ip = trim($ip); | |
| if (filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_NO_PRIV_RANGE | FILTER_FLAG_NO_RES_RANGE) !== false) { | |
| if (substr($ip, 0, 3) !== '127') { | |
| return $ip; | |
| } | |
| } | |
| } | |
| return $_SERVER['REMOTE_ADDR']; | |
| } | |
| $fromip = findip($allips); | |
| $realip = findip(array_reverse($allips)); | |
| $ip = findip(array_reverse($allips)); | |
| $username = "[email protected]"; //Cloudflare登入帳號 | |
| $api = "key"; //Cloudflare API KEY | |
| //Setting some variables for the request | |
| $hostname = 'xxx.domain.com'; //要更新的Domain | |
| $cloudflare = "https://www.cloudflare.com/api_json.html"; | |
| $request = "?a=DIUP&hosts=$hostname&u=$username&tkn=$api&ip=$ip"; | |
| $request_url = $cloudflare . $request; | |
| file_get_contents($request_url); | |
| echo "Success!"; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment