可能重复:
how can I make visitor counter in php?的访客计数器,当打开/关闭或离开页面
我要插入时,页面打开/关闭或离开,但没有onunload的..在下面的代码可以帮助我在打开页面时插入,但不会在关闭或离开时插入
session_start();
if (!isset($_SESSION["visits"]))
$_SESSION["visits"] = 0;
if ($_SESSION["visits"] > 1){
echo 'visit='.$_SESSION["visits"];
echo "You hit the refresh button!";}
else{
mysql_query(
"INSERT INTO najd_visit(visit_userId, visit_staticId, visit_page,
visit_enterTime)VALUES ('$userId', '$Sid', '$title', '$date') ");
$_SESSION["visits"] = $_SESSION["visits"] + 1;
echo 'visit='.$_SESSION["visits"];
echo "This is my site";
}
这是你第三次以某种形式提出这个问题。 http://stackoverflow.com/questions/10784163/how-unset-session-when-close-the-web-page-in-php,http://stackoverflow.com/questions/10862686/how-cani-i- make-visitor-counter-in-php –
是的,我是使用本网站的新用户...仍然尝试使用它 –
只有在需要更改您的措辞时才问一个问题并进行编辑。另外,请阅读常见问题解答:http://stackoverflow.com/faq –