-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpixel.php
More file actions
46 lines (38 loc) · 1.53 KB
/
pixel.php
File metadata and controls
46 lines (38 loc) · 1.53 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
<?php
// pixel.php - PIXEL INTELLIGENT
require_once 'config.php'; // Chemin à adapter
header('Content-Type: image/gif');
header('Access-Control-Allow-Origin: *');
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);
// 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
$data = [
'timestamp' => date('Y-m-d H:i:s'),
'ip_address' => $ip,
'user_agent' => $_SERVER['HTTP_USER_AGENT'] ?? '',
'page_url' => $_SERVER['HTTP_REFERER'] ?? 'direct',
'source' => $_GET['source'] ?? 'direct',
'campaign' => $_GET['campaign'] ?? '',
'country' => $geo['country'] ?? 'Unknown',
'city' => $geo['city'] ?? 'Unknown',
'click_data' => $_GET['click_data'] ?? '',
'viewport' => $_GET['viewport'] ?? '',
'session_id' => $_GET['session_id'] ?? ''
];
// INSERTION
$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) {
// Log erreur silencieusement
}
// PIXEL TRANSPARENT
echo base64_decode('R0lGODlhAQABAIAAAP///wAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw==');
?>