1<?php
2/**
3 * WHMCS GCLID-ONLY VISITOR LOGGER
4 * PURPOSE: Logs paid traffic journeys only and provides a secret clear link.
5 */
6
7add_hook('ClientAreaPage', 1, function($vars) {
8 // 1. SETTINGS & TIMEZONE
9 date_default_timezone_set('America/Chicago');
10 $logFile = dirname(__FILE__, 3) . '/whmcs_url_log.txt';
11 $secretKey = 'ts4upass123'; // Matches your WordPress secret
12
13 // 2. THE CLEAR LOG COMMAND
14 // Accessible via: yoursite.com/clients/index.php?clear_whmcs=ts4upass123
15 if (isset($_GET['clear_whmcs']) && $_GET['clear_whmcs'] === $secretKey) {
16 file_put_contents($logFile, "--- WHMCS LOG RESET BY ADMIN [" . date('Y-m-d h:i:s A') . "] ---\n\n");
17 header("Location: https://google.com");
18 exit;
19 }
20
21 // 3. CAPTURE DATA & PAID TRAFFIC FILTER
22 $whmcs_cookie = $_COOKIE['whmcs_gclid_final'] ?? 'NOT_FOUND';
23
24 // STOP HERE if it's not a paid visitor
25 if ($whmcs_cookie === 'NOT_FOUND') {
26 return;
27 }
28
29 $protocol = (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on' ? "https" : "http");
30 $fullUrl = $protocol . "://" . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
31
32 // 4. FILTER OUT BOT SIGNATURES (Safety layer)
33 if (strpos($fullUrl, 'language=') !== false || strpos($fullUrl, '&') !== false) {
34 return;
35 }
36
37 // 5. FORMAT VISUAL BLOCK
38 $timestamp = date('Y-m-d h:i:s A');
39 $ip = $_SERVER['REMOTE_ADDR'];
40
41 // Highlight if they are on the Email Verification page
42 $statusMarker = "💰 PAID VISITOR";
43 if (strpos($fullUrl, 'm=emailverification') !== false) {
44 $statusMarker = "📧 EMAIL VERIFICATION STAGE";
45 }
46
47 $logEntry = "==========================================================================" . PHP_EOL;
48 $logEntry .= "$statusMarker | TIME: [$timestamp CST]" . PHP_EOL;
49 $logEntry .= "GCLID: $whmcs_cookie" . PHP_EOL;
50 $logEntry .= "URL : $fullUrl" . PHP_EOL;
51 $logEntry .= "IP : $ip" . PHP_EOL;
52 $logEntry .= "==========================================================================" . PHP_EOL . PHP_EOL;
53
54 // 6. WRITE TO FILE
55 file_put_contents($logFile, $logEntry, FILE_APPEND);
56});