33 lines
1.4 KiB
PHP
33 lines
1.4 KiB
PHP
<?php
|
|
/**
|
|
* OPEN TRACKER v1 — Records email open via 1x1 pixel
|
|
* URL: /api/open.php?t=TRACKING_ID
|
|
* Injected as <img src="..."> in emails
|
|
*/
|
|
$tracking_id = $_GET['t'] ?? '';
|
|
|
|
if($tracking_id) {
|
|
$db = @pg_connect("host=localhost dbname=adx_system user=admin password=admin123");
|
|
if($db) {
|
|
pg_query($db, "SET search_path TO admin,public");
|
|
|
|
// Get recipient info
|
|
$r = pg_query_params($db, "SELECT recipient, isp FROM unified_send_log WHERE tracking_id=$1 LIMIT 1", [$tracking_id]);
|
|
$send = pg_fetch_assoc($r);
|
|
|
|
// Log open (deduplicate per tracking_id per hour)
|
|
pg_query_params($db, "INSERT INTO open_log (tracking_id, recipient, isp, ip_address, user_agent) SELECT $1,$2,$3,$4,$5 WHERE NOT EXISTS (SELECT 1 FROM open_log WHERE tracking_id=$1 AND opened_at > NOW() - INTERVAL '1 hour')",
|
|
[$tracking_id, $send['recipient']??'', $send['isp']??'', $_SERVER['REMOTE_ADDR']??'', $_SERVER['HTTP_USER_AGENT']??'']);
|
|
|
|
// Update tracking_opens
|
|
pg_query_params($db, "INSERT INTO tracking_opens (tracking_id, ip_address) VALUES ($1,$2) ON CONFLICT DO NOTHING",
|
|
[$tracking_id, $_SERVER['REMOTE_ADDR']??'']);
|
|
}
|
|
}
|
|
|
|
// Return 1x1 transparent pixel
|
|
header('Content-Type: image/gif');
|
|
header('Cache-Control: no-store, no-cache, must-revalidate');
|
|
header('Pragma: no-cache');
|
|
echo base64_decode('R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7');
|