Beispiel #1
0
<?php

const STATS = 'stats.json';
// prevent easy access
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
    // get old stats
    $stats = json_decode(file_get_contents(STATS));
    if (isset($stats->web->calculated)) {
        // compare saved day with server day
        if ((int) date('d') != $stats->updated) {
            include_once '../dependables.php';
            updateDay($stats);
        }
        // update confirmed and daily stats
        $stats->web->confirmed++;
        $stats->web->daily[0]++;
        $time = time();
        // a = days since names generated are confirmed
        // b = days since start of uinames.com
        $a = ($time - strtotime('Jan 16, 2016')) / 86400;
        $b = ($time - strtotime('Dec 23, 2013')) / 86400;
        // determine confirmed generated names
        $confirmed = $stats->web->confirmed / $a;
        // calculate avg generated names
        $stats->web->calculated = floor($confirmed * $b);
        // push new stats
        file_put_contents(STATS, json_encode($stats));
        echo 'Counted.';
    } else {
        echo 'Conflicted.';
    }
Beispiel #2
0
function send($content, $code = 200)
{
    $type = !empty($_GET['callback']) ? 'application/javascript' : 'application/json';
    header('Content-Type: ' . $type . '; charset=utf-8');
    header('Access-Control-Allow-Origin: *');
    header('Access-Control-Allow-Methods: GET');
    http_response_code($code);
    // use this for PHP <5.4 instead: header("HTTP/1.1 200 OK");
    $output = json_encode($content, JSON_UNESCAPED_UNICODE);
    // if (!DEBUGGING) ob_end_clean();
    if (!empty($_GET['callback'])) {
        // use JSONP
        echo $_GET['callback'] . '(' . $output . ');';
    } else {
        echo $output;
    }
    // it only counts if names are actually served
    if ($code == 200) {
        // get old stats
        $stats = json_decode(file_get_contents('stats.json'));
        // make sure file is not conflicted
        if (isset($stats->api->calculated)) {
            // compare saved day with server day
            if ((int) date('d') != $stats->updated) {
                include_once '../dependables.php';
                updateDay($stats);
            }
            // get amount
            $amount = isset($content['name']) ? 1 : count($content);
            // update confirmed and daily stats
            $stats->api->confirmed += $amount;
            $stats->api->daily[0] += $amount;
            $time = time();
            // a = days since names generated through the api are confirmed
            // b = days since api is live
            $a = ($time - strtotime('Jan 20, 2016')) / 86400;
            $b = ($time - strtotime('Oct 17, 2014')) / 86400;
            // determine confirmed generated names
            $confirmed = $stats->api->confirmed / $a;
            // calculate avg generated names
            $stats->api->calculated = floor($confirmed * $b);
            // push new stats
            file_put_contents('stats.json', json_encode($stats));
        }
    }
    exit;
}