views:

113

answers:

3

Looking for a simple way to show a welcome message to first time visitors on my website. What's the best approach?

+13  A: 

Using a cookie:

if (empty($_COOKIE['first_time'])) {
    show_welcome_message();
    setcookie("first_time", 1, time()+157680000);  /* expire in 5 years */
}

Of course, if the users clears his cookies, he'll see the message again. If he doesn't accept cookies, he'll see the message all the time.

Artefacto
+1: That's better approach.
Sarfraz
+1: code poetry!
Marco Demajo
A: 

Cookie. If the visitor doesn't have the cookie for your site, then display a welcome message. This isn't a foolproof method (it is trivial for a user to delete cookies), however it's the best you can do.

Lie Ryan
+2  A: 

Without an authenticated session (login), you're forced to using a cookie. If the cookie isn't present, set it and simultaneously display the welcome message.

Marcus Adams