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 outlook无法配置成功
  • ¥15 Pwm双极模式H桥驱动控制电机
  • ¥30 这是哪个作者做的宝宝起名网站
  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换