how can I make visitor counter in php? [closed]

喜欢而已 提交于 2019-12-01 11:41:22

To use $_SESSION, you need to call session_start() somewhere beforehand.

I think the code should look like this:

session_start();
if ( !isset($_SESSION['visited']) )
{
    echo "This is your first visit.";
    $_SESSION['visited'] = TRUE;

    // Do the MySQL query here
} else {
    echo "You hit the refresh button.";
}

echo "This is my site.";

This way, when a new user first visits your site (with a new session), his/her visit will be stored in the database and we will have a variable in the session set, so after a refresh button, the information about the visit won't be added to the database again.

Try add session_start() to handle your session request.

http://php.net/manual/en/function.session-start.php

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!