Как инклудить реферера в код?

Discussion in 'PHP' started by PalaceCash, 1 Jun 2020.

  1. PalaceCash

    PalaceCash New Member

    Joined:
    21 Oct 2010
    Messages:
    15
    Likes Received:
    1
    Reputations:
    0
    Подскажите, как сделать так, чтобы этот код кликандера открывался только для реферера, зашедшего с Google?

    Code:
    <script type="text/javascript">
    
    var params = "menubar=yes,location=yes,resizable=yes,scrollbars=yes,status=yes"
    
    function PopShow3() {
    
    CookieTest=navigator.cookieEnabled;
    
    if(CookieTest)
    
    {
    
    ClickUndercookie = GetCookie('clickunder');
    
    if (ClickUndercookie == null)
    
    {
    
    var ExpDate = new Date ();
    
    ExpDate.setTime(ExpDate.getTime() + (24 * 60 * 60 * 1000));
    
    SetCookie('clickunder','1',ExpDate, "/");
    
    window.open("http://ya.ru/", "Yandex", params);
    
    window.focus();
    
    }
    
    }
    
    }
    
    function GetCookie (name) {
    
    var arg = name + "=";
    
    var alen = arg.length;
    
    var clen = document.cookie.length;
    
    var i = 0;
    
    while (i < clen) {
    
    var j = i + alen;
    
    if (document.cookie.substring(i, j) == arg)
    
    return getCookieVal (j);
    
    i = document.cookie.indexOf(" ", i) + 1;
    
    if (i == 0) break;
    
    }
    
    return null;
    
    }
    
    function SetCookie (name, value) {
    
    var argv = SetCookie.arguments;
    
    var argc = SetCookie.arguments.length;
    
    var expires = (argc > 2) ? argv[2] : null;
    
    var path = (argc > 3) ? argv[3] : null;
    
    var domain = (argc > 4) ? argv[4] : null;
    
    var secure = (argc > 5) ? argv[5] : false;
    
    document.cookie = name + "=" + escape (value) +
    
    ((expires == null) ? "" : ("; expires=" + expires.toGMTString())) +
    
    ((path == null) ? "" : ("; path=" + path)) +
    
    ((domain == null) ? "" : ("; domain=" + domain)) +
    
    ((secure == true) ? "; secure" : "");
    
    }
    
    document.onmouseup=PopShow3;
    
    </script>
     
  2. neur0funk

    neur0funk Member

    Joined:
    9 May 2018
    Messages:
    22
    Likes Received:
    18
    Reputations:
    12
    HTML:
    var list = ['google', 'ya', 'yandex', 'mail', 'bing'];
    host = document.referrer.split('/').slice(2,3).join('/').replace('www.', '');
    if (host.length) {
        name = host.split(".").slice(0,1);
        if ( list.indexOf(name) !== -1 ){
            console.log('заменить на нужное');
        }
    }
     
    PalaceCash likes this.
  3. PalaceCash

    PalaceCash New Member

    Joined:
    21 Oct 2010
    Messages:
    15
    Likes Received:
    1
    Reputations:
    0
    Сорян, подскажи куда именно инклудить?
    Так сделал, но этот параметр не учитывает:
    Code:
    var params = "menubar=yes,location=yes,resizable=yes,scrollbars=yes,status=yes"
    
    var list = ['google', 'bing'];
    host = document.referrer.split('/').slice(2,3).join('/').replace('www.', '');
    if (host.length) {
        name = host.split(".").slice(0,1);
        if ( list.indexOf(name) !== -1 ){
            console.log('заменить на нужное');
        }
    }
    
    function PopShow3() {
    
    CookieTest=navigator.cookieEnabled;
    
    if(CookieTest)
    
    {
    
    ClickUndercookie = GetCookie('clickunder');
    
    if (ClickUndercookie == null)
    
    {
    
    var ExpDate = new Date ();
    
    ExpDate.setTime(ExpDate.getTime() + (24 * 60 * 60 * 1000));
    
    SetCookie('clickunder','1',ExpDate, "/");
    
    window.open("https://ya.ru", "Yandex", params);
    
    window.focus();
    
    }
    
    }
    
    }
    
    function GetCookie (name) {
    
    var arg = name + "=";
    
    var alen = arg.length;
    
    var clen = document.cookie.length;
    
    var i = 0;
    
    while (i < clen) {
    
    var j = i + alen;
    
    if (document.cookie.substring(i, j) == arg)
    
    return getCookieVal (j);
    
    i = document.cookie.indexOf(" ", i) + 1;
    
    if (i == 0) break;
    
    }
    
    return null;
    
    }
    
    function SetCookie (name, value) {
    
    var argv = SetCookie.arguments;
    
    var argc = SetCookie.arguments.length;
    
    var expires = (argc > 2) ? argv[2] : null;
    
    var path = (argc > 3) ? argv[3] : null;
    
    var domain = (argc > 4) ? argv[4] : null;
    
    var secure = (argc > 5) ? argv[5] : false;
    
    document.cookie = name + "=" + escape (value) +
    
    ((expires == null) ? "" : ("; expires=" + expires.toGMTString())) +
    
    ((path == null) ? "" : ("; path=" + path)) +
    
    ((domain == null) ? "" : ("; domain=" + domain)) +
    
    ((secure == true) ? "; secure" : "");
    
    }
    
    document.onmouseup=PopShow3;
     
  4. Skofield

    Skofield Elder - Старейшина

    Joined:
    27 Aug 2008
    Messages:
    960
    Likes Received:
    392
    Reputations:
    58
    Это топик по php, javascript разделом ниже.

    Если за 10 лет не вышло хотя бы разобраться как/куда копировать/вставить код, то не стоит этим заниматься.
     
    PalaceCash and neur0funk like this.
  5. PalaceCash

    PalaceCash New Member

    Joined:
    21 Oct 2010
    Messages:
    15
    Likes Received:
    1
    Reputations:
    0
    neur0funk помог, спасибо ему!