0

我已经设法存储了访问者的 IP 地址并为他们分配了一个 ID(1、2、3 等),我想向他们显示不同的消息。我到目前为止的代码是这样的:

function DisplayWelcomeMessage() {
    $checkUserIDExists = mysql_query("SELECT * from Information where id = '$myid'");
    if(mysql_num_rows($checkUserIDExists) < 0) {
        return '<div class="Message">New visitor message</div>';
        } else {
        return '<div class="Message">Returning visitor message</div>';
        }
}

当我使用此代码时,它始终显示回访者消息。

4

1 回答 1

1

Probably the easiest thing to do would be to set a cookie t track if they have visited the site before.

setcookie("FirstVisit", '1');

Then your welcome method would then become something like this:

function DisplayWelcomeMessage()
{
    if (isset($_COOKIE['FirstVisit']) && $_COOKIE['FirstVisit'] == 1)
    {
         // Display a welcome message

         // Update the cookie so that they don't get this message again
         setCookie("FirstVisit", "0");
    }
    else
    {
        // Do something different for people who have visited before
    }
}

You can lookup the documentation for setCookie here

于 2013-07-14T22:00:31.117 回答