【发布时间】:2015-05-21 19:56:43
【问题描述】:
我编写了一封 HTML 电子邮件,它呈现得很好,并且很少被退回。
客户希望根据用户的位置显示或隐藏电子邮件的某些部分。他们没有关于订阅者位置或任何列表分段的数据,所以我制作了一个从img 标签的src 加载的 PHP 脚本,并通过 DBIP API 返回基于用户 IP 的图像地理位置。
if ($info_array[1] == "US"){
if ($info_array[2] == ("New York" || "Connecticut" || "New Jersey")){
// log how many see the ny/nj/ct content into count.txt. protections are in place for multiple concurrent accesses
$fp = fopen('count.txt', 'c+');
flock($fp, LOCK_EX);
$count = (int)fread($fp, filesize('count.txt'));
ftruncate($fp, 0);
fseek($fp, 0);
fwrite($fp, $count + 1);
flock($fp, LOCK_UN);
fclose($fp);
// spit out the image
header('Content-Type: image/jpeg');
$image = readfile('box5.jpg');
return $image;
}
else{
header('Content-Type: image/gif');
$image = readfile('spacer.gif');
return $image;
}
}
else{
header('Content-Type: image/gif');
$image = readfile('spacer.gif');
return $image;
}
我在本地对此进行了测试,一切似乎都很好,但今天在服务器上打开 count.txt 时,它显示 8000/9000 次打开激活了脚本的 NY/CT/NJ 部分,这很疯狂,因为品牌在北美/南美都很受欢迎。
我的问题是:是我的代码中的错误导致了这种情况吗?或者请求是否来自邮件代理服务器?如果是这样,这些地区的大多数邮件代理是吗?
如果有帮助,我从 ExactTarget 发送了这个。
【问题讨论】:
-
值得注意的是,您的脚本中没有任何内容可以防止同一用户将计数增加两次。
-
真的,谢谢。我应该为此添加保护措施,但我不明白为什么有人会打开它这么多次,以至于它会以任何有意义的方式嘲笑统计数据。
标签: php email html-email