社区交流

php 留言板防刷新效果

?phpphp 留言板防刷新效果 $ip = $_SERVER[‘REMOTE_ADDR’]; $conn =
mysql_connect($mysql_server_name, $mysql_username,
$mysql_password); $sql = SELECT * FROM `my_counter` WHERE ip =
‘$ip’; mysql_select_db($mysql_database, $conn); $result =
mysql_query($sql); $row = mysql_fetch_row($result); print_r($row);
if(!$row) //如果IP没有出现过就新增 { $sql = INSERT INTO `my_counter`
( `new`, `ip`, `time_at`) VALUES (‘1’, ‘$ip’, NOW()); $result =
mysql_query($sql); } else //如果IP出现过 { $sql = SELECT TIME_TO_SEC(
NOW( ) ) – TIME_TO_SEC( time_at ) FROM `my_counter` WHERE `ip` =
‘$ip’ORDER BY `TIME_TO_SEC( NOW( ) ) – TIME_TO_SEC( time_at )`
ASC ; $result = mysql_query($sql); $row = mysql_fetch_row($result);
print_r($row); if($row[0]5) //如果IP出现过,则看他有没有超过5秒 {
$sql = INSERT INTO `my_counter` ( `new`, `ip`, `time_at`)
VALUES (‘1’, ‘$ip’, NOW()); $result = mysql_query($sql); } } $sql =
SELECT COUNT(*) FROM `my_counter`; $result = mysql_query($sql);
$row = mysql_fetch_row($result); print_r($row);
mysql_free_result($result); mysql_close($conn);?

发表评论

电子邮件地址不会被公开。 必填项已用*标注

相关文章