我试图在包含广告的div中记录用户对特定iFrame的点击,以阻止有问题的IP地址,从而防止那些试图垃圾广告的用户再次点击它。在用户每次单击时,都会将一条记录插入到mySQL数据库中的表中,其中包括:
每个用户/IP地址都有在24小时中单击广告3次的特权。为了检测iFrame广告上的每次点击,我使用了iframeTracker-jquery类并实现了一个JavaScript代码,如下所示:
index.php:
<?php include 'AdProtection.php'; ?>
<html>
<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>
<script src="js/jquery.iframetracker.js"></script>
<script>
jQuery(document).ready(function($) {
$('.iframetrack iframe').iframeTracker({
blurCallback: function() {
console.log("Click has been detected!");
$.ajax({
type: "POST",
url: "update.php"
);
}
});
});
</script>
</head>
<body>
<div class="iframetrack" id="adsense_frame">
<?php //Returns true when a user 's IP address isn't currently blocked by checking in Database. if(AdProtection::protectAd()) echo '<iframe width="728" height="90" src="js/demo/sample-iframe/red.html" frameborder="0" allowtransparency="true" scrolling="no"></iframe>'; ?>
</div>
</body>
</html>update.php:
<?php
function update($odb)
{
$sql=$odb->prepare('INSERT INTO system (ip, clicks, timestamp) VALUES(:ip, clicks+1, :timestamp) ON DUPLICATE KEY UPDATE clicks = clicks+1, timestamp = :timestamp');
$sql->execute(array(':ip' => ip2long($_SERVER['REMOTE_ADDR']),':timestamp' => time()));
}
//PDO Connection
include ( "db.php");
$sql=$odb->prepare('SELECT clicks, timestamp FROM system WHERE ip= :ip');
$sql->execute(array(':ip' => ip2long($_SERVER['REMOTE_ADDR'])));
$data = $sql->fetch();
if($data != null)
{
if($data['clicks'] % 3 == 0)
{
if(($data['timestamp'] + (24 * 60 * 60)) < time())
update($odb);
else
//User is currently blocked.
}
else
update($odb);
}
else
update($odb);在实现此JavaScript代码/ jQuery POST请求时,有两个关键问题:
我如何处理这些问题?
发布于 2015-05-13 12:31:06
您还可以决定不对某些ip地址或不依赖于客户端逻辑的设备指纹指纹显示iframe,这可能会使其比您提出的解决方案更安全。
https://stackoverflow.com/questions/30214286
复制相似问题