$url, CURLOPT_RETURNTRANSFER => true, CURLOPT_TIMEOUT => 30, CURLOPT_SSL_VERIFYPEER => true, ]); $headers = ['Content-Type: application/json']; if ($authHeader !== '') { $headers[] = 'Authorization: ' . $authHeader; } if ($method === 'POST') { curl_setopt($ch, CURLOPT_POST, true); $json = json_encode($payload); curl_setopt($ch, CURLOPT_POSTFIELDS, $json); $headers[] = 'Content-Length: ' . strlen($json); } curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); $body = curl_exec($ch); $httpCode = (int) curl_getinfo($ch, CURLINFO_HTTP_CODE); $err = curl_error($ch); curl_close($ch); if ($err !== '') { return ['ok' => false, 'error' => "cURL error: $err", 'http_code' => $httpCode]; } if ($httpCode < 200 || $httpCode >= 300) { return ['ok' => false, 'error' => "HTTP $httpCode - $body", 'http_code' => $httpCode]; } $decoded = json_decode($body, true); if (json_last_error() !== JSON_ERROR_NONE) { return ['ok' => false, 'error' => 'JSON decode error: ' . json_last_error_msg(), 'http_code' => $httpCode]; } return ['ok' => true, 'data' => $decoded, 'http_code' => $httpCode]; } // ─── 1. Capture the ClickFlare Click ID ───────────────────────── $cfClickId = $_GET['click_id'] ?? ($_GET['cf_click_id'] ?? ''); $cfClickId = trim($cfClickId); // ─── 2. Fetch date-level CPM and post RPV ──────────────────────── $postbackSent = false; $postbackResult = ''; $totalRpv = 0; $totalCpm = 0; $today = date('Y-m-d'); $apiError = ''; $loginHttpCode = null; $statsHttpCode = null; $statsRows = []; if ($cfClickId !== '') { $login = api_request(EXADS_LOGIN_URL, 'POST', [ 'api_token' => EXADS_API_TOKEN, ]); $loginHttpCode = $login['http_code'] ?? null; if (!$login['ok']) { $apiError = 'Login failed: ' . ($login['error'] ?? 'unknown error'); } else { $tokenType = $login['data']['type'] ?? 'Bearer'; $sessionToken = $login['data']['token'] ?? ''; if ($sessionToken === '') { $apiError = 'Login failed: no session token returned'; } else { $stats = api_request(EXADS_STATS_URL, 'POST', [ 'filter' => [ 'date_from' => $today, 'date_to' => $today, ], 'group_by' => [STATS_GROUP_BY], 'projection' => ['base'], 'limit' => 1, 'offset' => 0, ], "$tokenType $sessionToken"); $statsHttpCode = $stats['http_code'] ?? null; if (!$stats['ok']) { $apiError = 'Stats fetch failed: ' . ($stats['error'] ?? 'unknown error'); } else { $statsRows = $stats['data']['result'] ?? []; $statsRow = $statsRows[0] ?? []; $totalCpm = (float) ($statsRow['cpm'] ?? 0); $totalRpv = round($totalCpm / 1000, 6); } } } // ─── 3. Fire the ClickFlare postback ──────────────────────── if ($totalRpv > 0) { $postbackUrl = CLICKFLARE_POSTBACK . '?click_id=' . urlencode($cfClickId) . '&payout=' . urlencode((string) $totalRpv); $ch = curl_init(); curl_setopt_array($ch, [ CURLOPT_URL => $postbackUrl, CURLOPT_RETURNTRANSFER => true, CURLOPT_TIMEOUT => 10, CURLOPT_FOLLOWLOCATION => true, CURLOPT_SSL_VERIFYPEER => true, ]); $postbackResult = curl_exec($ch); $httpCode = (int) curl_getinfo($ch, CURLINFO_HTTP_CODE); curl_close($ch); $postbackSent = ($httpCode >= 200 && $httpCode < 300); } } // ─── 4. Build debug log ────────────────────────────────────────── $debug = []; $debug[] = '=== Click Stats Debug ==='; $debug[] = 'Timestamp: ' . date('Y-m-d H:i:s'); $debug[] = 'click_id: ' . ($cfClickId ?: '(none)'); $debug[] = 'Stats date: ' . $today; $debug[] = 'Group by: ' . STATS_GROUP_BY; $debug[] = 'Login HTTP: ' . ($loginHttpCode ?? 'N/A'); $debug[] = 'Stats HTTP: ' . ($statsHttpCode ?? 'N/A'); $debug[] = ''; $debug[] = '--- API ---'; if ($apiError !== '') { $debug[] = 'Error: ' . $apiError; } $debug[] = 'Rows returned: ' . count($statsRows); $debug[] = ''; $debug[] = '--- Calculation ---'; $debug[] = 'Aggregate CPM: ' . $totalCpm; $debug[] = 'RPV: ' . $totalRpv . ' (CPM / 1000)'; $debug[] = ''; $debug[] = '--- Postback ---'; if ($totalRpv > 0) { $debug[] = 'Postback URL: ' . ($postbackUrl ?? 'N/A'); $debug[] = 'HTTP status: ' . ($httpCode ?? 'N/A'); $debug[] = 'Sent OK: ' . ($postbackSent ? 'YES' : 'NO'); $debug[] = 'Response: ' . ($postbackResult ?: '(empty)'); } else { $debug[] = ' (skipped — RPV is 0 or missing data)'; } $debugOutput = implode("\n", $debug); // ─── 5. Render the normal Viral Page HTML ──────────────────────── ?> NEW EPISODE

WATCH EPISODE 1

On yo phone now!

```