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

Show content only once per IP!

Discussion in 'HTML & JavaScript' started by vodkaa, Dec 2, 2013.

  1. vodkaa

    vodkaa Junior Member

    Joined:
    May 23, 2013
    Messages:
    119
    Likes Received:
    23
    Hello folks,


    What I want is to show certain content (image) only once for each visitors of my website based on their IP address (or anything).


    Is there a way to do this?


    Thanks.
     
  2. webwhizz

    webwhizz BANNED BANNED

    Joined:
    Apr 3, 2011
    Messages:
    724
    Likes Received:
    659
    hey maybe something like this will work

    Code:
    // check if they've been here, if they haven't set
    // a cookie for subsequent visits
    if($_COOKIE['beenhere']) { 
        setcookie("beenhere", '1');
    }
    else {
        // where you want them to go if they've seen this page
        header('Location: http://www.example.com/');
     
    • Thanks Thanks x 1
  3. bytzu

    bytzu Junior Member

    Joined:
    Jun 30, 2011
    Messages:
    101
    Likes Received:
    142
    Don't forget to set expiration time for the cookie else it will expire at the end of the session and the user will see the same content again when visiting your website.

    setcookie("CookieName", $CookieValue, time()+3600); /* -3600 sec expire in 1 hour */