为什么代码users_online在刷新时自动递增

时间:2010-09-30 08:09:31

标签: php

当我刷新此页面时,用户是自动增量

<?
    $session= session_id();
    $time=time();
    $time_check=$time-600; //SET TIME 10 Minute
    include "conf.php" ;
    $tbl_name="user_online"; /// Table name
     //search for session id in database
    $result=mysql_query("SELECT * FROM $tbl_name WHERE session='$session'" );
    $count=mysql_num_rows($result);
    if($count=="0"){
      // if not found insert
    $result1=mysql_query("INSERT INTO $tbl_name(session, time)VALUES('$session', '$time')");
    }
    else {
      // if found update data
    $result2=mysql_query("UPDATE $tbl_name SET time='$time' WHERE session = '$session'");

    }
    $result3=mysql_query("SELECT * FROM $tbl_name");
    $count_user_online=mysql_num_rows($result3);
    echo "User online : $count_user_online ";
    // if over 10 minute, delete session
    $result4=mysql_query("DELETE FROM $tbl_name WHERE time<$time_check");

    mysql_close();
    // Open multiple browser page for result
    ?>

1 个答案:

答案 0 :(得分:1)

也许你没有开始会话?请添加页眉session_start();代码。