-
Notifications
You must be signed in to change notification settings - Fork 28
/
t.php
119 lines (106 loc) · 3.6 KB
/
t.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
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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
<?php
include('includes/config.php');
//--------------------------------------------------------------//
function dbConnect() { //Connect to database
//--------------------------------------------------------------//
// Access global variables
global $mysqli;
global $dbHost;
global $dbUser;
global $dbPass;
global $dbName;
// Attempt to connect to database server
if(isset($dbPort)) $mysqli = new mysqli($dbHost, $dbUser, $dbPass, $dbName, $dbPort);
else $mysqli = new mysqli($dbHost, $dbUser, $dbPass, $dbName);
// If connection failed...
if ($mysqli->connect_error) {
fail();
}
global $charset; mysqli_set_charset($mysqli, isset($charset) ? $charset : "utf8");
return $mysqli;
}
//--------------------------------------------------------------//
function fail() { //Database connection fails
//--------------------------------------------------------------//
print 'Database error';
exit;
}
// connect to database
dbConnect();
?>
<?php
include('includes/helpers/geo/geoip.inc');
include('includes/helpers/short.php');
header("Cache-Control: no-cache, must-revalidate");
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
//----------------------------------------------------------------//
//get variable
$i = mysqli_real_escape_string($mysqli, $_GET['i']);
$i_array = explode('/', $i);
$campaign_id = short($i_array[0], true);
$userID = short($i_array[1], true);
if(array_key_exists(2, $i_array)) $ares = $i_array[2];
else $ares = '';
//get user's client
$useragent = $_SERVER['HTTP_USER_AGENT'];
//get user's ip address & country code
if (getenv("HTTP_CLIENT_IP")) {
$ip = getenv("HTTP_CLIENT_IP");
} elseif (getenv("HTTP_X_FORWARDED_FOR")) {
$ip = getenv("HTTP_X_FORWARDED_FOR");
} else {
$ip = getenv("REMOTE_ADDR");
}
$ip_array = explode(',', $ip);
if(array_key_exists(1, $ip_array)) $ip = trim($ip_array[0]);
$gi = geoip_open("includes/helpers/geo/GeoIP.dat",GEOIP_STANDARD);
$country = geoip_country_code_by_addr($gi, $ip);
geoip_close($gi);
$time = time();
//if this is an autoresponder email,
$val = '';
if(count($i_array)==3 && $i_array[2]=='a')
$q = 'SELECT opens FROM ares_emails WHERE id = '.$campaign_id;
else
$q = 'SELECT opens FROM campaigns WHERE id = '.$campaign_id;
$r = mysqli_query($mysqli, $q);
if ($r && mysqli_num_rows($r) > 0)
{
while($row = mysqli_fetch_array($r))
{
$opens = $row['opens'];
if($opens=='')
$val = $userID.':'.$country;
else
{
$opens .= ','.$userID.':'.$country;
$val = $opens;
}
}
}
//Set open
//if this is an autoresponder email,
if(count($i_array)==3 && $i_array[2]=='a')
$q = 'UPDATE ares_emails SET opens = "'.$val.'" WHERE id = '.$campaign_id;
else
$q = 'UPDATE campaigns SET opens = "'.$val.'" WHERE id = '.$campaign_id;
$r = mysqli_query($mysqli, $q);
if ($r){}
//Just in case this user is set to bounced because Amazon can't deliver it the first time.
//If user opens the newsletter, it means user did not bounce, so we set bounced to 0
$q = 'SELECT email FROM subscribers WHERE id = '.$userID.' AND bounced = 1';
$r = mysqli_query($mysqli, $q);
if ($r && mysqli_num_rows($r) > 0)
{
while($row = mysqli_fetch_array($r))
{
$email = stripslashes($row['email']);
$q = 'UPDATE subscribers SET bounced = 0, timestamp = '.$time.' WHERE email = "'.$email.'" AND last_campaign = '.$campaign_id;
$r = mysqli_query($mysqli, $q);
if ($r){}
}
}
//----------------------------------------------------------------//
header("Location: ".APP_PATH."/img/to.png");
return;
?>