How to: Display a “welcome back” message to your visitors

What about displaying a customized welcome message to your readers? Do you know that you can use the cookie sended by the comment form to get the name of the reader? Let’s use it to create a very cool welcome message.

Nothing hard here: Simply paste the following code wherever you want on your template.

<?php
if(isset($_COOKIE['comment_author_'.COOKIEHASH])) {
    $lastCommenter = $_COOKIE['comment_author_'.COOKIEHASH];
    echo "Welcome Back ". $lastCommenter ."!";
} else {
    echo "Welcome, Guest!";
}
?>

First, we checked if the visitor have a cookie called comment_author_xxx. If he have, we can get his name and display it on the welcome message. If the cookie doesn't exists, we simply welcome the visitor as a guest.

Credits goes to ifohdesigns for this awesome script!

20 Responses

Nov 18 2008 15:26

hi
thanks for your great site & great job
i would love to know ” how crate a Archive page like you did”
i will waitng for your recipe .

Nov 18 2008 15:41

@kamran: Why not! Get the rss feed so you’ll not miss it =)

Nov 18 2008 16:03

i am in for 2 month
i am fan of your site
:p

Nov 18 2008 18:59

That’s good to hear =)

Nov 18 2008 19:36

Thanks jbj and ifoh for this cool tip!

Nov 19 2008 00:23

You’re welcome! Glad it helped.

Nov 19 2008 00:40

Great site, I’ve been following it for over a month now on RSS and find these small little tips to be extremely useful.

This latest welcome back message is cool, how about one for just new readers?

Nov 19 2008 00:44

@Dave: That’s a great idea for a future recipe, thank you =)

Nov 20 2008 09:16

The best site ever. Congrats. Keep doing this wonderful work. M.

Nov 20 2008 09:18

@Mike: hehe, this is flattering althought I’m don’t agree with you ;) Thanks!

Dec 23 2008 06:04

Thanks for the useful tutorial! I think a welcome back message can be handy if utilized properly.

Apr 16 2009 09:06

Thanks for the useful tip!

Trackbacks:

Leave a Comment

* Name, Email, Comment are Required