Skip to content

Instantly share code, notes, and snippets.

@jerry74
Last active August 29, 2015 14:06
Show Gist options
  • Select an option

  • Save jerry74/fe657519f7f9620a804a to your computer and use it in GitHub Desktop.

Select an option

Save jerry74/fe657519f7f9620a804a to your computer and use it in GitHub Desktop.

Revisions

  1. jerry74 revised this gist Sep 5, 2014. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions gistfile1.php
    Original file line number Diff line number Diff line change
    @@ -32,8 +32,8 @@ function findip($allips) {
    $realip = findip(array_reverse($allips));
    $ip = findip(array_reverse($allips));

    $username = "[email protected]"; //cloudfare登入帳號
    $api = "key"; //cloudfare API KEY
    $username = "[email protected]"; //Cloudflare登入帳號
    $api = "key"; //Cloudflare API KEY

    //Setting some variables for the request
    $hostname = 'xxx.domain.com'; //要更新的Domain
  2. jerry74 created this gist Sep 5, 2014.
    45 changes: 45 additions & 0 deletions gistfile1.php
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,45 @@
    <?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]"; //cloudfare登入帳號
    $api = "key"; //cloudfare 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!";