- // php限制用户60秒后发布评论实例代码
- /*
- create table `test`.`abc` (
- `id` int( 4 ) not null auto_increment ,
- `times` int( 4 ) not null default '0',
- `ip` varchar( 200 ) null default null ,
- primary key ( `id` )
- ) engine = myisam
- */
- if( $_post )
- {//开源代码Vevb.com
- $conn = mysql_connect('localhost','root','root') or die('mysql server 2001');
- mysql_select_db('test',$conn);
- $date = time();
- $ip = $_server['remote_addr'];//获取ip地址,这是测试所以没作判断了
- $wait = "select times,ip from abc where ip='$ip' and ($date-times<60) order by id desc limit 1";
- $rows = mysql_query($wait ) or die( mysql_error());
- if( mysql_num_rows( $rows ) )
- {
- die('坐下来休息一下吧,您的动作太快了,请60秒后再发布你的信息!');
- }
- else
- {
- $sql = "insert into abc(times,ip) values('$date','$ip')";
- $insert = mysql_db_query('test',$sql,$conn);
- if( $insert )
- {
- echo '评论成功';
- }
- else
- {
- echo '评论失败';
- }
- }
- }
- ?>
- method="post" action="">
- ="textfield">
- "text" name="Vevb.com" id="textfield">
- "submit" name="button" id="button" value="发表评论">
新闻热点
疑难解答