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
2010-06-20 16:16:51
+1: That's better approach.
Sarfraz
2010-06-20 16:19:45
+1: code poetry!
Marco Demajo
2010-06-21 21:26:02
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
2010-06-20 16:17:54
+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
2010-06-20 16:30:18