电脑安全

您当前的位置:主页 > 电脑安全 >

php 留言板防刷新-网络编程

来源:[db:来源]标题:   看他    编辑:电脑技术全能网 时间:2019-09-20 06:24

原标题: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);?>