1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

iframe show max 3 times for each visitor per 24 hrs

Discussion in 'HTML & JavaScript' started by mylikes786, Feb 3, 2014.

  1. mylikes786

    mylikes786 Registered Member

    Joined:
    Oct 31, 2013
    Messages:
    80
    Likes Received:
    6
    <iframe src="http://google.com" width="10%" height="20%" scrolling="No" frameborder="0"></iframe>

    i am using that type iframe on my site.
    I want it show max 3 time for each visitor in per 24 hrs

    How can i do this
     
  2. Schvamp

    Schvamp Power Member

    Joined:
    Feb 13, 2012
    Messages:
    684
    Likes Received:
    549
    Location:
    Hogwarts
    I would use a function to set a cookie. Set it to expire after X, on each visit increase the value of visits if bellow 3 and show the iframe. Else if 3 don't do anything and wait for the cookie to expire. PHP.
    Sorry I couldn't provide you with a code snippet right now tho..
     
  3. mypmmail

    mypmmail Junior Member

    Joined:
    Jan 31, 2008
    Messages:
    111
    Likes Received:
    27
    I think you can try something like this.

    Code:
    <?php
    
    $n = 0;
    if (isset($_COOKIE["show"])) {
    	$n = $_COOKIE["show"];
    } else {
    	$expire=time()+60*60*24;
    	setcookie("show", 0 , $expire);
    }
    
    if ($n < 3) {
    	setcookie("show", ($n + 1));
    	echo "show iframe";
    } else {
    	echo "don't show iframe";
    }
    ?>
    
     
  4. rutix

    rutix Junior Member

    Joined:
    Sep 6, 2012
    Messages:
    102
    Likes Received:
    12
    There is no need for checking. Just set the cookies to last 8 hours