PHP wordpress cookie redirect

Solution:

Try this WordPress Action

You can try this method. Just add the name of your cookie and add this code to your Functions.php file, located at the root of your theme file. If is not there you can just create one.

Paste code into your Functions.php file

function has_auth_cookie(){ 
    // See if cookie is set
    if(isset($_COOKIE['cookie_name'])){
        // Do nothing 
    }else{
        // Do Something else
        header('Location: http://www.example.com/');
    }
}
add_action('template_redirect', 'has_auth_cookie');

Conclusion

WordPress has a great Action and Filter system which makes adding code easy as cake. By using the filters and actions you can keep your code nice and clean instead of throwing PHP all over your template files. This method will survive WordPress core updates as well. Which is the only way to go if your using WordPress.