Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I have a page like a welcome page which should be visited only once by each subscriber. After registration, they will redirected on my welcome page. Then I want that page not be available on same user for the second time, if the will try, I want them to be redirected. Is this possible?, should I use plugin? Thanks. :)

share|improve this question
    
What you want probably isn't strictly possible. If you set a cookie, there is always a chance that the user has deleted it. You can work around this for logged in users by tracking them in the db, but even together you don't have 100% certainty that the users will not get back to that "one time only" page. That may be the best you can do though. –  s_ha_dum Dec 10 '12 at 14:56
add comment

1 Answer

Following code should work. Please replace page ID and redirected url with your own.

add_action( 'send_headers', 'welcome_redirect' );
function welcome_redirect() {
    global $wp;
    // check if it is a welcome page
    if($wp->query_vars['p'] == 1){
        if(empty($_COOKIE['welcome_visited']))
            setcookie("welcome_visited", 1, time()+3600000, "/");   // set cookie 
        else {
            header('Location: '.get_site_url()); // redirect to homepage
            exit;
        }
    }
}
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.