forked from backupbrain/php-email-open-tracking
-
Notifications
You must be signed in to change notification settings - Fork 0
/
trackerimage.jpg.php
59 lines (50 loc) · 1.89 KB
/
trackerimage.jpg.php
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
<?php
// Function to get the client IP address
function get_client_ip() {
$ipaddress = '';
if (getenv('HTTP_CLIENT_IP'))
$ipaddress = getenv('HTTP_CLIENT_IP');
else if(getenv('HTTP_X_FORWARDED_FOR'))
$ipaddress = getenv('HTTP_X_FORWARDED_FOR');
else if(getenv('HTTP_X_FORWARDED'))
$ipaddress = getenv('HTTP_X_FORWARDED');
else if(getenv('HTTP_FORWARDED_FOR'))
$ipaddress = getenv('HTTP_FORWARDED_FOR');
else if(getenv('HTTP_FORWARDED'))
$ipaddress = getenv('HTTP_FORWARDED');
else if(getenv('REMOTE_ADDR'))
$ipaddress = getenv('REMOTE_ADDR');
else
$ipaddress = 'UNKNOWN';
return $ipaddress;
}
// trackerimage.jpg.php
// You are collecting some info about your users
// in this case it's the email campaign they've opened...
$campaignID = intval($_GET['campaignID']);
// and the subscription ID - you saved that from your
// double opt-in registration, right?
$subscriptionID = intval($_GET['subscriptionID']);
// Get more info:
// Get Ip
$ip = get_client_ip();
// Get user Agent
$userAgent = $_SERVER['HTTP_USER_AGENT'];
// load the Database abstractor
require_once('settings.php');
require_once('classes/EmailTracker.class.php');
// someone accessed this script by opening an email
// and displaying images. Let's store that knowledge
$mysql_date_now = date("Y-m-d H:i:s");
$EmailCampaign = new EmailTracker($campaignID, $settings['mysql']);
$EmailCampaign->openedBy( $subscriptionID, $mysql_date_now, $ip, $userAgent );
// load the image
$image = 'images/image.jpg';
// getimagesize will return the mimetype for this image
$imageinfo = getimagesize($image);
$image_mimetype = $imageinfo['mime'];
// tell the browser to expect an image
header('Content-type: '.$image_mimetype);
// send it an image
echo file_get_contents($image);
?>