如何使用PHP和MySQL跟踪页面刷新

时间:2016-10-18 03:15:32

标签: php mysql

嘿伙计我需要帮助跟踪所有用户的网页刷新情况。我知道我需要下面编写的代码但是我需要将它存储在名为“pagecounter”的表中的MySQL数据库中,该表包含两列“id”和“count”。提前致谢!

<?php
$query = "UPDATE pagecounter
          SET count = 1
          WHERE id = 1";

session_start();
$_SESSION['count'] = 0;
$output =  "";

if ( isset( $_SESSION['count'] ) ) 
{
    echo "{$_SESSION['count']}\n";
$_SESSION['count'] = $_SESSION['count'] + 1;
}
else {

    $_SESSION['count'] = 0;
}

?>

1 个答案:

答案 0 :(得分:0)

像这样更改你的代码,

<?php


session_start();
$output =  "";

if ( isset( $_SESSION['count'] ) ) 
{
echo "{$_SESSION['count']}\n";
$_SESSION['count'] = $_SESSION['count'] + 1;
}
else {

$_SESSION['count'] = 0;
}
$query = "UPDATE pagecounter
      SET count = ".$_SESSION['count']."
      WHERE id = ".$_SESSION['userid']." ";
?>