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 Power Member

    Joined:
    Apr 3, 2011
    Messages:
    696
    Likes Received:
    656
    Occupation:
    P-R-0
    Location:
    scotland
    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 Registered Member

    Joined:
    Jun 30, 2011
    Messages:
    96
    Likes Received:
    137
    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 */