-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathimage-tracker.php
More file actions
87 lines (72 loc) · 2.81 KB
/
image-tracker.php
File metadata and controls
87 lines (72 loc) · 2.81 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
<?php
// image-tracker.php - IMAGE PNG AVEC TRACKER INTÉGRÉ
// https://gael-berru.com/smart_phpixel/image-tracker.php?source=social&campaign=partage
//
require_once 'config.php';
header('Content-Type: image/png');
header('Access-Control-Allow-Origin: *');
header('Cache-Control: no-store, no-cache, must-revalidate, max-age=0');
try {
$pdo = new PDO("mysql:host=".DB_HOST.";dbname=".DB_NAME.";charset=utf8", DB_USER, DB_PASS);
$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
// Récupération des données
$requestData = $_SERVER['REQUEST_METHOD'] === 'POST' ? $_POST : $_GET;
// GÉOLOCALISATION
$ip = $_SERVER['HTTP_X_FORWARDED_FOR'] ?? $_SERVER['REMOTE_ADDR'];
$geo = json_decode(file_get_contents("http://ip-api.com/json/{$ip}"), true);
// DONNÉES DE TRACKING
$data = [
'timestamp' => date('Y-m-d H:i:s'),
'ip_address' => $ip,
'user_agent' => $_SERVER['HTTP_USER_AGENT'] ?? '',
'page_url' => $_SERVER['HTTP_REFERER'] ?? ($requestData['page_url'] ?? 'direct'),
'source' => $requestData['source'] ?? 'direct',
'campaign' => $requestData['campaign'] ?? '',
'country' => $geo['country'] ?? 'Unknown',
'city' => $geo['city'] ?? 'Unknown',
'image_type' => $requestData['image_type'] ?? 'tracking',
'shared_by' => $requestData['shared_by'] ?? '',
'click_data' => $requestData['click_data'] ?? '',
'viewport' => $requestData['viewport'] ?? '',
'session_id' => $requestData['session_id'] ?? ''
];
// INSERTION EN BASE
$stmt = $pdo->prepare("
INSERT INTO ".DB_TABLE."
(timestamp, ip_address, user_agent, page_url, source, campaign, country, city, click_data, viewport, session_id)
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
");
$stmt->execute(array_values($data));
} catch(Exception $e) {
error_log("Image Tracker Error: " . $e->getMessage());
}
// CRÉATION D'UNE IMAGE PNG DYNAMIQUE
$width = 800;
$height = 600;
$image = imagecreate($width, $height);
// Couleurs
$white = imagecolorallocate($image, 255, 255, 255);
$black = imagecolorallocate($image, 0, 0, 0);
$blue = imagecolorallocate($image, 67, 97, 238);
// Fond blanc
imagefill($image, 0, 0, $white);
// Texte de l'image
$texts = [
"Smart Pixel Analytics",
"Image de Tracking",
"Partagée par: " . ($_GET['shared_by'] ?? 'Utilisateur'),
"Campagne: " . ($_GET['campaign'] ?? 'Générale'),
date('d/m/Y H:i:s')
];
$y = 100;
foreach ($texts as $text) {
imagestring($image, 5, 50, $y, $text, $black);
$y += 40;
}
// QR Code simple (simulé)
imagestring($image, 3, 50, 300, "🔍 QR Code de Tracking", $blue);
imagestring($image, 2, 50, 330, "Scannez-moi pour voir les stats!", $black);
// Génération de l'image
imagepng($image);
imagedestroy($image);
?>