douyu8187 2015-05-21 19:56
浏览 19
已采纳

GeoIP和HTML电子邮件

I coded up an HTML email, which rendered fine, and delivered with few bounces.

The client wanted to show or hide certain sections of the email depending on the user's location. They don't have data on their subscriber's locations or any list segmentation, so I made a PHP script that is loaded from an img tag's src, and returns the image based on the IP of the user via the DBIP API for geolocation.

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;
}

I tested this locally and all seemed to be well and good, but upon opening count.txt on the server today it showed that 8000/9000 opens activated the NY/CT/NJ part of the script, which is crazy because the brand is popular all over North / South America.

My question is: is it a fault in my code that caused this? Or would the request have come from mail proxy servers? If so, are most mail proxies in these areas?

If it helps, I sent this from ExactTarget.

  • 写回答

1条回答 默认 最新

  • dsbc80836 2015-05-21 20:06
    关注

    I think it's your fault because of this:

    if ($info_array[2] == ("New York" || "Connecticut" || "New Jersey"))
    

    Order of execution is the following:

    ("New York" || "Connecticut" || "New Jersey") is true

    Next - compare $info_array[2] to true

    And any $info_array[2] except empty values or zeros will be true.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 用ns3仿真出5G核心网网元
  • ¥15 matlab答疑 关于海上风电的爬坡事件检测
  • ¥88 python部署量化回测异常问题
  • ¥30 酬劳2w元求合作写文章
  • ¥15 在现有系统基础上增加功能
  • ¥15 远程桌面文档内容复制粘贴,格式会变化
  • ¥15 关于#java#的问题:找一份能快速看完mooc视频的代码
  • ¥15 这种微信登录授权 谁可以做啊
  • ¥15 请问我该如何添加自己的数据去运行蚁群算法代码
  • ¥20 用HslCommunication 连接欧姆龙 plc有时会连接失败。报异常为“未知错误”