1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

How to limit page view only ONCE per visitor via cookie?

Discussion in 'WordPress' started by lowriderzzz, Oct 4, 2020.

  1. #1
    Hi!

    Is there a way within WordPress by (pasting some sort of a script I guess) make so I can restrict certain page on my site to be seen only once. And if the visitor decides to refresh or to enter it again in the browser to redirect him to another page.

    I have managed to find a script that redirects visitors after some time is spent on the page, but I couldn't manage to find a script that could to also limit the number of views of a user per page... is there just a copy-paste script that could just do that? (sorry but my coding skills are only good enough to just copy-paste a code... and probably replace some basic values)

    *if there is something unclear, please let me know, so I can further explain.

    Thank you and have a good one!
     
    lowriderzzz, Oct 4, 2020 IP
  2. PosterDesigns

    PosterDesigns Peon

    Messages:
    9
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    1
    #2
    Courtesy of https://wordpress.stackexchange.com/questions/82211/how-to-detect-first-visit-of-a-user/82215 try something like this maybe:

    <?php
    function is_first_time()
    {
        if (isset($_COOKIE['_wp_first_time']) || is_user_logged_in()) {
            return false;
        }
    
        $domain = COOKIE_DOMAIN ? COOKIE_DOMAIN : $_SERVER['HTTP_HOST'];
    
        // expires in 30 days.
        setcookie('_wp_first_time', '1', time() + (WEEK_IN_SECONDS * 4), '/', $domain);
    
        return true;
    }
    
    if (is_first_time()) {
         // it's the user's first time, do stuff!
    }
    Code (markup):
     
    PosterDesigns, Dec 22, 2020 IP