• I need to find out how to set a code that would do something like this.

    <?php if_first-time-visitor
    then do this
    else do this ?>

    I’d like for it to plant a cookie the first time they visit and then check to see if they have it to make sure a welcome code doesn’t get repeated to them. Please help me out with this it would make my day. Thanks in advance!

Viewing 6 replies - 1 through 6 (of 6 total)
  • Moderator Ipstenu (Mika Epstein)

    (@ipstenu)

    🏳️‍🌈 Advisor and Activist

    Thread Starter J B

    (@kreuzian)

    Not sure what to do. Correct me if I’m wrong.

    if (!get_cookie(‘new_visitor’)) { —INSERTING code here would work BEFORE cookie planted??—-
    // cookie not set, first visit

    // create cookie to avoid hitting this case again
    $cookie = array(
    ‘name’ => ‘new_visitor’,
    ‘value’ => ‘Yes’,
    ‘expire’ => time()+86500,
    ‘domain’ => ‘.my-domain.com’,
    ‘path’ => ‘/’,
    ‘prefix’ => ”,
    );
    set_cookie($cookie);
    }

    Thanks for the help.

    Thread Starter J B

    (@kreuzian)

    Basically if I put my code I only want to activate once, like my welcome message, in the spot mentioned above it would work only once, and then the cookie is planted right? and since it is activated only if it can NOT get_cookie then it wouldn’t activate again right?

    just checking. thanks again.

    Thread Starter J B

    (@kreuzian)

    This is a code I wrote to test it to say “hello”, but it says:
    Fatal error: Call to undefined function get_cookie()

    <?php if (!get_cookie('new_visitor')) {?> hello <?php } ?>
    // cookie not set, first visit
    
    // create cookie to avoid hitting this case again
    $cookie = array(
    'name' => 'new_visitor',
    'value' => 'Yes',
    'expire' => time()+86500,
    'domain' => 'mysite.com',
    'path' => '/',
    'prefix' => '',
    );
    set_cookie($cookie);
    }
        ?>

    How can I fix it?

    Thread Starter J B

    (@kreuzian)

    oops I saw one of my own errors in the code but the problem remains. are you suggesting I have to use codeigniter with wordpress? isn’t it a seperate platform?

    How can I achieve this in wordpress without codeigniter. The cookiehelper doesn’t work.

    Try reading up on the w3 site: http://www.w3schools.com/PHP/php_cookies.asp

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘if_new-visitor-to-website?? how to set PHP to check?’ is closed to new replies.