curl_setopt($session, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1); curl_setopt($session, CURLOPT_HTTPHEADER, getRelevantRequestHeaders()); curl_setopt($session, CURLOPT_HEADER, false); curl_setopt($session, CURLOPT_RETURNTRANSFER, true); curl_setopt($session, CURLOPT_SSL_VERIFYPEER, FALSE); curl_setopt($session, CURLOPT_SSL_VERIFYHOST, 2); $response = curl_exec($session); header("Content-Type: application/xml"); header(getStatusMessage("".curl_getinfo($session, CURLINFO_HTTP_CODE))); echo $response; curl_close($session); break; case 'HEAD': rest_head($request); break; case 'DELETE': rest_delete($request); break; case 'OPTIONS': rest_options($request); break; default: rest_error($request); break; } } else { header("HTTP/1.0 400 Bad Request"); }
* but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. */ //require_once('config.php'); require_once 'functions.php'; header('Content-Type: application/json'); if (teampass_api_enabled() != "1") { echo '{"err":"API access not allowed."}'; exit; } teampass_whitelist(); parse_str($_SERVER['QUERY_STRING']); $method = $_SERVER['REQUEST_METHOD']; $request = explode("/", substr(@$_SERVER['PATH_INFO'], 1)); switch ($method) { case 'GET': rest_get(); break; case 'PUT': rest_put(); break; case 'DELETE': rest_delete(); break; case 'HEAD': rest_head(); break; default: rest_error('UNKNOWN'); break; }
function rest_get($request) { rest_head($request); // ... // echo "do something bro\n"; }
function rest_get($request) { rest_head($request); // ... // echo 'do something bro\\n'; }
function rest_get($request) { rest_head($request); // ... // $db = mysqli_connect(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME); // ... // if ($db) { // Get Donations // $donation = NULL; $result = mysqli_query($db, "SELECT * FROM wp_donations"); while ($row = mysqli_fetch_array($result)) { $donation[] = $row; // same as array_push(...), but faster; } echo "Total: " . count($donation) . "\n"; // Eliminate duplicate e-mail addresses, to build database of users // $byAddress = array(); $donation_count = count($donation); for ($idx = 0; $idx < $donation_count; $idx++) { $mail = strtolower($donation[$idx]["email"]); if (array_key_exists($mail, $byAddress)) { $byAddress[$mail]['total'] += floatval($donation[$idx]["amount"]); $byAddress[$mail]['donations']++; if ($byAddress[$mail]['user']) { $byAddress[$mail]['user'] = intval($donation[$idx]["user_id"]); } } else { $byAddress[$mail] = array(id => $idx, donation_id => intval($donation[$idx]["ID"]), user => intval($donation[$idx]["user_id"]), total => 0.0 + floatval($donation[$idx]["amount"]), donations => 1, newuser => 0); } } // Search all missing users // $userless = 0; $newusers = 0; $byAddress_values = array_keys($byAddress); $byAddress_count = count($byAddress); for ($idx = 0; $idx < $byAddress_count; $idx++) { $key = $byAddress_values[$idx]; $item =& $byAddress[$key]; // If no user set, Search // if ($item["user"] === 0) { $userless++; if ($item["newuser"] === 0) { $result = mysqli_query($db, "SELECT ID FROM wp_users WHERE user_email='" . $key . "'"); while ($row = mysqli_fetch_array($result)) { //print_r($row); $item["newuser"] = $row['ID']; $newusers++; } } } } echo "Unique: " . count($byAddress) . "\n\n"; $byAddress_values = array_keys($byAddress); $byAddress_count = count($byAddress); for ($idx = 0; $idx < $byAddress_count; $idx++) { $key = $byAddress_values[$idx]; $item = $byAddress[$key]; echo "[" . $idx . "] " . $key . " [" . $item["id"] . "] = " . $item["total"] . " (" . $item["donations"] . ")" . " -- " . $item["user"] . " [" . $item["newuser"] . "]" . ($item["total"] > 200 ? " * * * *" : "") . "\n"; } echo "Userless: " . $userless . "\n"; echo "New Users Found: " . $newusers . "\n"; // * * * // mysqli_close($db); // * * * // } echo "\n"; }
$id = $request[1]; } else { $id = null; } switch ($method) { case 'PUT': rest_put($table, $id, $db); break; case 'POST': rest_post($table, $id, $db); break; case 'GET': rest_get($table, $id, $db, $params); break; case 'HEAD': rest_head($table, $id, $db); break; case 'DELETE': rest_delete($table, $id, $db); break; case 'OPTIONS': rest_options($table, $id, $db); break; default: rest_error(); break; } } function rest_put($table, $id = null, $db, $data) { /*