How I can count visitors ?? I want to insert when open the page and when close or leave the page but not onunload And I don't want to insert when refresh the page the below code help me to insert when open the page , but not help when close
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";
}
Try add session_start() to handle your session request.
http://php.net/manual/en/function.session-start.php