Solution:1
Bumped into this one – I recommend against adding a new cookie, instead I would hijack (take advantage of) the current cookie and let WP manage it for you. Additionally the hooks available in WP allow very clean and tight code using WP features – try the snippet below – I put in comments and tried to be verbose :
function custom_set_newuser_cookie() {
// re: http://codex.wordpress.org/Function_Reference/get_currentuserinfo
if(!isset($_COOKIE)){ // cookie should be set, make sure
return false;
}
global $current_user; // gain scope
get_currentuserinfo(); // get info on the user
if (!$current_user->user_login){ // validate
return false;
}
setcookie('sitename_newvisitor', $current_user->user_login, time()+1209600, COOKIEPATH, COOKIE_DOMAIN, false); // change as needed
}
// http://codex.wordpress.org/Plugin_API/Action_Reference/wp_login
add_action('wp_login', 'custom_set_newuser_cookie'); // will trigger on login w/creation of auth cookie
/**
To print this out
if (isset($_COOKIE['sitename_newvisitor'])) echo 'Hello '.$_COOKIE['sitename_newvisitor'].', how are you?';
*/
And yes, use functions.php for this code. Good luck.