Control a page impressions to show different ads

Discussion in 'PHP' started by banana8, Dec 9, 2012.

  1. #1
    Hello everybody,

    I would like to set a specific page to show X on the first impression, and then to show Y on the next impression, and to make this work forever.
    Please advise on how to implement that kind of behavior, or where should I look for.

    Appreciate
     
    banana8, Dec 9, 2012 IP
  2. Rukbat

    Rukbat Well-Known Member

    Messages:
    2,908
    Likes Received:
    37
    Best Answers:
    51
    Trophy Points:
    125
    #2
    When the user connects to the site, look for a cookie. If there's none, or if there is one, but it doesn't say that it's not the first visit, show X. If there's a cookie and it says it's not the first visit, show Y. (If you want to show different things on each visit, look for the number in the cookie ans show what you want for that number visit.)

    Then send a cookie saying it's not the first visit. (Or if you want to keep track of the number of visits, and you read a cookie, the number in the cookie plus 1.)

    Look for how to use Javascript to send and read cookies.
     
    Rukbat, Dec 9, 2012 IP
  3. scottlpool2003

    scottlpool2003 Well-Known Member

    Messages:
    1,708
    Likes Received:
    49
    Best Answers:
    9
    Trophy Points:
    150
    #3
    That's a good method but cookies are a dangerous game these days with the new laws introduced regarding cookies in the EU.

    If you are going for this type of implementation, I'd strongly urge you to familiarize yourself with this article: http://www.ico.gov.uk/for_organisations/privacy_and_electronic_communications/the_guide/cookies.aspx

    Another way you could do it is store the users IP address in a database and do what Rukbat suggested which would be to have a page counter in a table and increment it by 1 assigned to the users IP.
     
    scottlpool2003, Dec 10, 2012 IP
  4. Rukbat

    Rukbat Well-Known Member

    Messages:
    2,908
    Likes Received:
    37
    Best Answers:
    51
    Trophy Points:
    125
    #4
    This would be a user interface customization cookie which, they say, "can be exempted from informed consent under certain conditions if they are not used for additional purposes"

    You're not storing any information about the user, so "First party analytics cookies are not likely to create a privacy risk if websites provide clear information about the cookies to users and privacy safeguards, eg a user friendly mechanism to opt out from any data collection and where they ensure that identifiable information is anonymised." At very worst, that would mean a "I agree to let the site know that I've been here before" checkbox.

    As far as using the user's IP, that won't work too well these days, with people logging in with phones and laptops from all over the place. (Where I live, the big cable provider provides wifi almost all over a huge area, and you get a different IP each time. Then there's McDonalds, Starbucks, Sam's Club, the local library, etc., etc.)
     
    Rukbat, Dec 10, 2012 IP
    scottlpool2003 likes this.