Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to determine real user are browsing my site or just crawling or else in PHP

I want to know whether a user are actually looking my site(I know it's just load by the browser and display to human, not actually human looking at it).

I know two method will work.

  1. Javascript.

    If the page was load by the browser, it will run the js code automatically, except forbid by the browser. Then use AJAX to call back the server.

  2. 1×1 transparent image of in the html.

    Use img to call back the server.

Do anyone know the pitfall of these method or any better method?

Also, I don't know how to determine a 0×0 or 1×1 iframe to prevent the above method.

like image 460
Magic Avatar asked Feb 23 '23 15:02

Magic


2 Answers

  1. A bot can access a browser, e.g. http://browsershots.org

  2. The bot can request that 1x1 image.

In short, there is no real way to tell. Best you could do is use a CAPTCHA, but then it degrades the experience for humans.

Just use a CAPTCHA where required (user sign up, etc).

like image 151
alex Avatar answered Feb 26 '23 04:02

alex


I want to know whether a user are actually looking my site(I know it's just load by the browser and display to human, not actually human looking at it).

The image way seems better, as Javascript might be turned off by normal users as well. Robots generally don't load images, so this should indeed work. Nonetheless, if you're just looking to filter a known set of robots (say Google and Yahoo), you can simply check for the HTTP User Agent header, as those robots will actually identify themselves as being a robot.

like image 43
Berry Langerak Avatar answered Feb 26 '23 05:02

Berry Langerak