1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Spoof referer, set useragent (fake useragent) and redirect visitor to custom url

Discussion in 'PHP' started by mi6hq, Dec 16, 2017.

  1. #1
    Hi,

    I receive visitors in bulk but those are from such source that I don't want to show so I wish to either spoof http_referer or completely blank http_referer. And also set custom useragent and then forward visitor to custom url. So in short here is what I want to do.

    1. Make http_referer "blank" or set "custom referer".
    2. Set custom useragent
    3. Redirect visitor to custom url

    To do all this I have following code:


    <?php
    
    // Same code can be used to set custom referer
    
    echo fetchpage();
    
    function fetchpage()
    {
        $desturl = "http://www.tracemyip.org";
    
        $referers = array("google.com", "yahoo.com", "msn.com", "ask.com", "live.com");
        $choice = array_rand($referers);
        $referer = "http://" . $referers[$choice] . "";
    
        $browsers = array("Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/50.0.2638.0 Safari/537.36",
                 "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/48.0.2564.82 Safari/537.36 OPR/35.0.2066.37",
                 "Mozilla/5.0 (Windows NT 10.0; WOW64; rv:45.0) Gecko/20100101 Firefox/45.0",
                 "Mozilla/5.0 (Windows NT 6.2) AppleWebKit/537.36 (KHTML, like Gecko) Dragon/43.3.3.185 Chrome/43.0.2357.81 Safari/537.36");
        $choice2 = array_rand($browsers);
        $browser = $browsers[$choice2];
    
        $headers[] = 'Accept: image/gif, image/x-bitmap, image/jpeg, image/pjpeg,text/html,application/xhtml+xml';
        $headers[] = 'Connection: Keep-Alive';
        $headers[] = 'Content-type: application/x-www-form-urlencoded;charset=UTF-8';
        $useragent = $browser;
    
        $process = curl_init($desturl);
        curl_setopt($process, CURLOPT_HTTPHEADER, $headers);
        curl_setopt($process, CURLOPT_HEADER, 0);
        curl_setopt($process, CURLOPT_USERAGENT, $useragent);
        curl_setopt($process, CURLOPT_REFERER, $referer);
        curl_setopt($process, CURLOPT_TIMEOUT, 30);
        curl_setopt($process, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($process, CURLOPT_FOLLOWLOCATION, 1);
    
        $return = curl_exec($process);      
        curl_close($process);      
        return $return;
    }
    
    ?>
    Code (markup):
    So far this code is work well for these 2 tasks:

    1. This code can set custom useragent
    2. This code can set fake referer
    3. After setting custom useragent and referer how to redirect visitor to custom url ($desturl) ?

    Can someone help me please?

    MI6
     
    mi6hq, Dec 16, 2017 IP
  2. mi6hq

    mi6hq Member

    Messages:
    87
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    41
    #2
    As I searched on Internet there is some meta refresh method used to do this. There are many free websites to blank referer but I want to set this function in my own script so not only I can remove actual referer but also can set referer of my choice as per my requirement.

    For example then I will be able to send traffic @ 80% blank referer (direct), 10% from social media sites and 10% from other custom sites. So this is what I want to do. Or any traffic ratio as per requirement.

    MI6
     
    mi6hq, Dec 16, 2017 IP
  3. phpmillion

    phpmillion Member

    Messages:
    145
    Likes Received:
    11
    Best Answers:
    4
    Trophy Points:
    45
    #3
    You can't really do that at the same time. Let me explain why...

    If you redirect user (no matter if you use header, meta-refresh, or some else technique) the original page (the same one you redirect user to) will see user's original user agent because user will get website's content right from websites server, not from your script.

    In short, the same second you redirect user to some other server, his user agent becomes visible to server (no matter how many times you changed user agent in your script before that point).
     
    phpmillion, Dec 17, 2017 IP
  4. NetStar

    NetStar Notable Member

    Messages:
    2,471
    Likes Received:
    541
    Best Answers:
    21
    Trophy Points:
    245
    #4
    If you are receiving span traffic block the IPs. Don't waste your time trying to play games with them. What you are trying to do is not possible.
     
    NetStar, Dec 20, 2017 IP