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
1  
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

2 Answers 2

up vote 1 down vote accepted

As mentioned in a comment above the cookie solution will not totally do the trick. If it's ok that they can revisited the welcome page from a different browser or if they delete cookies. This is fine.

If not I would use the database. I think easiest would be to regard the time the user was registered.

Like if the user registered within the last 60 minutes offer the welcome page. If not forward somewhere else.

This solution does not require you to alter the database and does not have the drawbacks of the cookie. If you want to offer a limited time offer for newly registered this might be a good way. You can even combine this with the cookie. That way you make sure the visitor can only see it once on his first device. And if he logs in on his second device more than 60 minutes later he will not see it either.

share|improve this answer
    
Thanks for clarifying, makes more sense. Thanks @Christoph –  markyeoj Jun 28 at 5:24
add comment

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.