How to detect fake users ( crawlers ) and cURL

前端 未结 6 930
-上瘾入骨i
-上瘾入骨i 2020-12-02 04:12

Some other website use cURL and fake http referer to copy my website content. Do we have any way to detect cURL or not real web browser ?

6条回答
  •  生来不讨喜
    2020-12-02 04:40

    The way of avoid fake referers is tracking the user

    You can track the user by one or more of this methods:

    1. Save a cookie in the browser client with some special code (ex: last url visited, a timestamp) and verify it in each response of your server.

    2. Same as before but using sessions instead of explicit cookies

    For cookies you should add cryptographic security like.

    [Cookie]
    url => http://someurl/
    hash => dsafdshfdslajfd
    

    hash is calulated in PHP by this way

    $url = $_COOKIE['url'];
    $hash = $_COOKIE['hash'];
    $secret = 'This is a fixed secret in the code of your application';
    
    $isValidCookie = (hash('algo', $secret . $url) === $hash);
    
    $isValidReferer = $isValidCookie & ($_SERVER['HTTP_REFERER'] === $url)
    

提交回复
热议问题