Display welcome message to first-time visitors

前端 未结 3 1769
遇见更好的自我
遇见更好的自我 2021-02-09 23:33

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

相关标签:
3条回答
  • 2021-02-09 23:52

    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.

    0 讨论(0)
  • 2021-02-10 00:00

    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.

    0 讨论(0)
  • 2021-02-10 00:13

    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.

    0 讨论(0)
提交回复
热议问题