How to show a script only Once every 180 days

YoutubeSlanger

Junior Member
Joined
Nov 9, 2011
Messages
184
Reaction score
22
I got a script that is working wonders for me its basically a content lock modified but the problem is I just dont know how to make it show once every 180 days to a visitors, I know I have to cookie it but I just dont know how I spend countless days weeks reading up on it and Im just a idiot I guess, And I like to do everything myself cause I just feel good about doing it lol. But i hit a road block.

this is my JS

Code:
 var Delay = 0;//Seconds after them clicking the link, the gateway vanishes. 
    var AppearDelay = 35;//Seconds before gateway appears
    var oldHistLength = history.length;
        var ssDelay = 50;//
    var stop_scroll = false;


    var oldHistLength = history.length;
setInterval ( "checkHistory()", 100 );


function setVisibility(id, visibility) {
document.getElementById(id).style.display = visibility;
}


function checkHistory() {
if (oldHistLength != history.length)
   {
   setVisibility('sub3', 'none');
   setVisibility('sub4', 'inline');
   oldHistLength = history.length;
   }
   }



 
    

    function scrolltop(){
    if(stop_scroll==true){
        scroll(0,0);
    }
}
    

    function delayappearance()
    {
        setTimeout("setupgateway()", AppearDelay*1000);
        
    }


    
    function setupgateway()
    
    {
        stop_scroll = true;
        window.scrollTo(0,0);
        document.body.style.overflow = "hidden"
        var Left = $(window).width() /2;
        Left = Left - $('#gatewaydiv').width()/2;
        
        var Top = $(window).height() /2;
        Top = Top - $('#gatewaydiv').height()/2;
        
        $('#gatewaydiv').css('top', Top+'px').css('left', Left+'px').css('display', 'inline');
        $('#gatewayDimmer').width($('html').width());
        $('#gatewayDimmer').height($('html').height());
        $('#gatewayDimmer').css('display','block');
        

    }

 
    function removegateway()
    {
        stop_scroll = false;
        document.body.style.overflow = ""
        $('#gatewaydiv').css('display', 'none');
        $('#gatewayDimmer').css('display','none');
    }
            setTimeout('removegateway()', ssDelay*1000);


    $(document).ready(function()
    {
        $('.offerlink').click(function()
        {
            setTimeout('removegateway()', Delay*1000);
        });


        delayappearance();
    });


How do I cookie this to only show once every 180 days or x amount I want to display.... any help is greatly appreciated
 
Just set a cookie after the gateway shows for 180 days.

Wrap the gateway show code in an if() statement that checks for the cookie.
 
Chances are cookies will be erased within that ~6 month period, so you're better off using a database to store the unique IP, a time stamp it was last shown to this particular IP, and then using PHP, query the database to see if the time has lapsed, and print that script you have above.

The same could be done with a cookie, which is much much less resource intensive but like I hinted at earlier, it's far more inaccurate since cookies can be cleared at any given moment.

The cookie route is easier, too, and can be demonstrated within this post. See below. If you want to go the IP-correlated route, PM me.

Place this code anywhere as long as it's included in the same file and above the code snippet below this code snippet:
Code:
<?php
    $display_code = false;
    if(isset($_COOKIE["last_displayed"]) && is_numeric($_COOKIE["last_displayed"]))
    {
        if(time() - $_COOKIE["last_displayed"] >= 15552000)
        {
            setcookie("last_displayed", time(), mktime(0, 0, 0, 12, 31, 2020)); // will expire 12/31/2020
            $display_code = true;
        }
    }
    else
    {
        setcookie("last_displayed", time(), mktime(0, 0, 0, 12, 31, 2020)); // will expire 12/31/2020
        $display_code = true;
    }
?>

This code will display your script:

Code:
<?php
    if($display_code)
    {
?>
    var Delay = 0;//Seconds after them clicking the link, the gateway vanishes.
    var AppearDelay = 35;//Seconds before gateway appears
    var oldHistLength = history.length;
        var ssDelay = 50;//
    var stop_scroll = false;


    var oldHistLength = history.length;
setInterval ( "checkHistory()", 100 );


function setVisibility(id, visibility) {
document.getElementById(id).style.display = visibility;
}


function checkHistory() {
if (oldHistLength != history.length)
   {
   setVisibility('sub3', 'none');
   setVisibility('sub4', 'inline');
   oldHistLength = history.length;
   }
   }



 
    

    function scrolltop(){
    if(stop_scroll==true){
        scroll(0,0);
    }
}
    

    function delayappearance()
    {
        setTimeout("setupgateway()", AppearDelay*1000);
        
    }


    
    function setupgateway()
    
    {
        stop_scroll = true;
        window.scrollTo(0,0);
        document.body.style.overflow = "hidden"
        var Left = $(window).width() /2;
        Left = Left - $('#gatewaydiv').width()/2;
        
        var Top = $(window).height() /2;
        Top = Top - $('#gatewaydiv').height()/2;
        
        $('#gatewaydiv').css('top', Top+'px').css('left', Left+'px').css('display', 'inline');
        $('#gatewayDimmer').width($('html').width());
        $('#gatewayDimmer').height($('html').height());
        $('#gatewayDimmer').css('display','block');
        

    }

 
    function removegateway()
    {
        stop_scroll = false;
        document.body.style.overflow = ""
        $('#gatewaydiv').css('display', 'none');
        $('#gatewayDimmer').css('display','none');
    }
            setTimeout('removegateway()', ssDelay*1000);


    $(document).ready(function()
    {
        $('.offerlink').click(function()
        {
            setTimeout('removegateway()', Delay*1000);
        });


        delayappearance();
    });
<?php
    }
?>

Note: I haven't tested this, so adjust everything so it'll show once every 1 minute, and make sure it works. To do that, adjust this line of code

if(time() - $_COOKIE["last_displayed"] >= 15552000)

to look like this:

if(time() - $_COOKIE["last_displayed"] >= 60)
 
Last edited:
Just set a cookie after the gateway shows for 180 days.

Wrap the gateway show code in an if() statement that checks for the cookie.

thats the problem man I dont know how to do that

I use this code to redirect the user to the exact same page but with out the locker, It only shows it to the user once every 60 days I can easily change that, which is fine but im trying to implement this on over 6,000 pages so this is not practical, if i have it implemented on the content locker is great cause I can just copy the script into the theme.

Code:
// page to go to if cookie exists
go_to = "enter website here";

// number of days cookie lives for
num_days = 60;
function ged(noDays){
    var today = new Date();
    var expr = new Date(today.getTime() + noDays*24*60*60*1000);
    return  expr.toGMTString();
}

function readCookie(cookieName){
    var start = document.cookie.indexOf(cookieName);
    if (start == -1){ 
        document.cookie = "ttt33=yes; expires=" + ged(num_days);
    } else {
        window.location = go_to;
    }
}
readCookie("ttt33");
 
Chances are cookies will be erased within that ~6 month period, so you're better off using a database to store the unique IP, a time stamp it was last shown to this particular IP, and then using PHP, query the database to see if the time has lapsed, and print that script you have above.

The same could be done with a cookie, which is much much less resource intensive but like I hinted at earlier, it's far more inaccurate since cookies can be cleared at any given moment.

The cookie route is easier, too, and can be demonstrated within this post. See below. If you want to go the IP-correlated route, PM me.

Place this code anywhere as long as it's included in the same file and above the code snippet below this code snippet:
Code:
<?php
    $display_code = false;
    if(isset($_COOKIE["last_displayed"]) && is_numeric($_COOKIE["last_displayed"]))
    {
        if(time() - $_COOKIE["last_displayed"] >= 15552000)
        {
            setcookie("last_displayed", time(), mktime(0, 0, 0, 12, 31, 2020)); // will expire 12/31/2020
            $display_code = true;
        }
    }
    else
    {
        setcookie("last_displayed", time(), mktime(0, 0, 0, 12, 31, 2020)); // will expire 12/31/2020
        $display_code = true;
    }
?>
This code will display your script:

Code:
<?php
    if($display_code)
    {
?>
    var Delay = 0;//Seconds after them clicking the link, the gateway vanishes.
    var AppearDelay = 35;//Seconds before gateway appears
    var oldHistLength = history.length;
        var ssDelay = 50;//
    var stop_scroll = false;


    var oldHistLength = history.length;
setInterval ( "checkHistory()", 100 );


function setVisibility(id, visibility) {
document.getElementById(id).style.display = visibility;
}


function checkHistory() {
if (oldHistLength != history.length)
   {
   setVisibility('sub3', 'none');
   setVisibility('sub4', 'inline');
   oldHistLength = history.length;
   }
   }



 
    

    function scrolltop(){
    if(stop_scroll==true){
        scroll(0,0);
    }
}
    

    function delayappearance()
    {
        setTimeout("setupgateway()", AppearDelay*1000);
        
    }


    
    function setupgateway()
    
    {
        stop_scroll = true;
        window.scrollTo(0,0);
        document.body.style.overflow = "hidden"
        var Left = $(window).width() /2;
        Left = Left - $('#gatewaydiv').width()/2;
        
        var Top = $(window).height() /2;
        Top = Top - $('#gatewaydiv').height()/2;
        
        $('#gatewaydiv').css('top', Top+'px').css('left', Left+'px').css('display', 'inline');
        $('#gatewayDimmer').width($('html').width());
        $('#gatewayDimmer').height($('html').height());
        $('#gatewayDimmer').css('display','block');
        

    }

 
    function removegateway()
    {
        stop_scroll = false;
        document.body.style.overflow = ""
        $('#gatewaydiv').css('display', 'none');
        $('#gatewayDimmer').css('display','none');
    }
            setTimeout('removegateway()', ssDelay*1000);


    $(document).ready(function()
    {
        $('.offerlink').click(function()
        {
            setTimeout('removegateway()', Delay*1000);
        });


        delayappearance();
    });
<?php
    }
?>
Note: I haven't tested this, so adjust everything so it'll show once every 1 minute, and make sure it works. To do that, adjust this line of code

if(time() - $_COOKIE["last_displayed"] >= 15552000)

to look like this:

if(time() - $_COOKIE["last_displayed"] >= 60)


yeah I tested this and my locker no longer pops up anymore at all. help
 
Last edited:
Sorry guys for being slow I figured it out I used a lil bit of Crazy code and lil but of my old cookie and made it work
 
Back
Top