dongyou2714 2016-06-03 16:32 采纳率: 0%
浏览 45

PHP - 检测是否是正在打开链接的人

this problem has been killing me and I could not find a solution.

I implement a scoring system based on links in PHP.

A person "A" can post a link on social networks like Twitter and when another person "B" open this link, the individual A wins 10 points.

The problem is that when the link is posted on twitter for example. It opens so many times giving too many points to the other person.

I have tried to identify the User agent in PHP to determine when a human opens the link, but some twitter hits look like this:

Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/47.0.2526.111 Safari/537.36

This could clearly be a human, but it is not, Because that user agent opened twice the link in the same second with 2 different IP. 52.19.163.13 and 52.16.66.216. If I'm not mistaken are Amazon servers.

Even I excluded all the robots in robots.txt but is not working. This is the way I try to identify a human.

$app->get('/link/:code', function($codigo){

if(is_human() and !is_bot())
{
   $res = $db->giveCoins($codigo);

    if ($res !== 0) {

    echo "Redirect to another page"; //cannot be a human interaction on this page

    }else
        {
        echo "Robot";
        }
}

});

And these are the functions I use to analyze the User Agent:

function is_bot(){

$botlist = array("Gigabot", "Googlebot",
                "FlipboardProxy", "Purebot", 
                "facebookexternalhit","applebot",
                "Google-HTTP-Java-Client",
                "Chrome/33.0.0.0");

foreach($botlist as $bot){
if(strpos($_SERVER['HTTP_USER_AGENT'],$bot)!==false)
return true;    // Is a bot
}
return false;    // Not a bot
}        

function is_human(){

$humanlist = array("Android","Safari",
                  "Chrome","OPR","Opera",
                  "Chromium","Firefox");

foreach($humanlist as $bot){
if(strpos($_SERVER['HTTP_USER_AGENT'],$bot)!==false)
return true;    // Probably a human
}
return false;    // Probably not a human
}

I do not know if there is a smarter way to determine if is a human who opens the link. Thanks for the attention

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 微信小程序协议怎么写
    • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
    • ¥20 怎么用dlib库的算法识别小麦病虫害
    • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
    • ¥15 java写代码遇到问题,求帮助
    • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
    • ¥15 有了解d3和topogram.js库的吗?有偿请教
    • ¥100 任意维数的K均值聚类
    • ¥15 stamps做sbas-insar,时序沉降图怎么画
    • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看